0

I'm using HtmlService in google sheets.

code.gs:

function openDialog() {
  var html = HtmlService.createTemplateFromFile('Index')
    .evaluate()
    .setHeight(300);

  SpreadsheetApp.getUi().showModalDialog(html, 'Dialog title');
}

Index.html:

<form>
<input type="text" name="userid" value="<? getProp(userKey,true) ?>"/>
<input type="button" value="Submit" onClick="google.script.run.withSuccessHandler().processForm(this.form)"/>
</form>

Can I somehow check if the user closes the window without clicking on my submit button? I want to force the user to provide the data.

Daavis
  • 23
  • 5
  • You can not force the user to provide an answer. You could record that the form was opened, but unless you have a way of identifying the user, that won't help you. Are you requiring the user to log in? – Alan Wells May 08 '17 at 23:37
  • So how can I check that form was opened? – Daavis May 09 '17 at 06:57
  • In ui.promt script wait until user action. I'm looking for something similar but for more inputs. – Daavis May 09 '17 at 07:03
  • You can use an anonymous function in the onload event `window.onload = function() {//To Do - code here to record that the form was opened}` – Alan Wells May 09 '17 at 12:23
  • Refer with this [SO post](http://stackoverflow.com/questions/2229942/how-to-block-users-from-closing-a-window-in-javascript). However, as Sandy Good stated, it is not a good practice to force the user to provide an answer. You may want to take a look at [`onBeforeUnload`](http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm). *"It wont force someone to stay but it will prompt them asking them whether they really want to leave, which is probably the best cross browser solution you can manage."* – abielita May 09 '17 at 15:46

0 Answers0