简体   繁体   中英

How to display alert windows or prompt to unregistered users

I am setting up a spreadsheet whose users do not necessarily have a Google account nor should be required to log in.

I would like to interact with users in two ways that are possible with the Browser class. One is displaying an alert in a pop-up window, in order to warn users not to edit a field. This is done with Browser.msgBox or ̀ ui.alert . The second thing is requesting an input in a window, which is done nicely with Browser.inputBox() .

While my code works fine when I am logged in as owner, it is useless when edited by an unregistered user.

Can I make those function work for unregistered users and if so, how?

Otherwise, are there workarounds to achieve similar functionalities?

Here is a minimal example of what I did:

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSheet();   
  var eventRange = event.range;   
  var eventRow = eventRange.getRow();
  var eventCol = eventRange.getColumn();
  if(eventCol == 1){
    protectDateField(ss, eventRow, eventCol)
    }
  }

  function protectDateField(ss, eventRow, eventCol){
    var ui = SpreadsheetApp.getUi();
    ui.alert("Do Not Edit This Field!");
    ss.getRange(eventRow,eventCol).clearContent(); 
    }

Short answer

What you want to do it's not possible on Google Sheets.

Explanation

  • To run a script bounded to a spreadsheet the user should be an editor for that spreadsheet.
  • Simple triggers can't access services that require authorization to run.
  • Some additional restrictions apply when triggers are triggered by anonymous users.

NOTES:

  1. The required authorization scopes by each method are included on the documentation section for each method.
  2. Anonymous users can't authorize scripts to be ran by installable triggers as the authorization process requires a usar account to log the respective authorization.

For further details see:

Workarounds

There is no way to achieve the desired functionality by solely using Google Sheets, but you could

  • create a web app by using Apps Script and embed on it a spreadsheet
  • create a web app by using another platform and embed on it spreadsheet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM