Google apps javascript doesn't run for anonymous users?

不问归期 提交于 2020-06-25 06:54:43

问题


This is probably a dumb newbie question, but I have a spreadsheet that I want to make available to anonymous users by just giving them the URL. After a lot of hair-pulling I now have the cell protection rain dance figured out, but I have another problem.

The original sheet's onOpen works fine for me and creates a custom menu, but when I share the sheet and open it as an anonymous user, no menu appears. Fine, thought I, it isn't the first time Google's stuff doesn't work as advertised. So then I went ahead and created a button to do the action that the missing menu couldn't do. Same story. Button appears to anonymouse user but it is dead. No action on click.

It doesn't seem possible that javascript would be disabled for anonymous users, but that's what it looks like. Any suggestions?


回答1:


I think you're right user3550481. I replicated what you described above and made up this spreadsheet to test what you reported. It has a "My Menu" menu that should appear onOpen and a button with a script assigned to the same function. It didn't make any difference whether Sharing was set to "Anyone with the link" or "Public". I even tried Publishing the script as a webapp accessible to Anyone even anonymous - I didn't expect that to make any difference because it obviously has no doGet function - and it didn't.

When I tested as an anonymous user, i.e. not signed into any Google account, the "My Menu" menu did not show up and the button was, as you say, dead.

Once I signed into a Google account, both worked but intriguingly the revision history shows the results as anonymous.

I'll be very interested to see if anyone offers a better solution than reporting it to the Issue Tracker - if you don't I probably will. In the meantime, whenever you share the link with your users the best thing would be to explain that they'll need to sign in to a Google account for it to work properly - which after all is free.

Script used in the spreadsheet:

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var myMenu = [ {name: 'My Menu', functionName: 'myMenu'}];
  ss.addMenu('My Menu', myMenu);
}

function myMenu() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName('Sheet1');
  var lr = sh.getLastRow()+1;
  sh.getRange(lr, 1).setValue('Clicking My Menu worked!');
}


来源:https://stackoverflow.com/questions/23164091/google-apps-javascript-doesnt-run-for-anonymous-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!