4

When you append any Google Sheet URL with "&rm=minimal" (omitting the double quotes) - the Sheet will very nicely render in any browser without the Tool Bar or Formula bar.

This frees up a lot of space and is great for applications where you don't want/need those screen elements - and you just want users to see the sheet.

However, I have a couple of onOpen commands in my associated script which does not run in a sheet whose URL has been modified with "&rm=minimal"

  function onOpen() {
    SpreadsheetApp.getActiveSheet().getRange('test!A1').clearContent(); 
    SpreadsheetApp.getActiveSheet().getRange('test!A15').clearContent();
}

Does anyone know why this is happening -- and if there is a workaround?

player0
  • 124,011
  • 12
  • 67
  • 124
blafarm
  • 69
  • 1
  • 10
  • Script editor> view > executions. Any failure logs? – TheMaster Jul 04 '19 at 05:55
  • 1
    I couldn't find anything about this yet, but I noticed that onEdit() functions do work with this parameter. I think the onOpen trigger has something to do with the menus loading first. – Jescanellas Jul 04 '19 at 10:07
  • Thank you Jescannellas. Your observation provided me with the means to develop a workaround. Although, I do wish there was some code snippet that I could run at the top of my script to 'satisfy' and fool Google Scripts into making onOpen commands work when the GUI is minimized. – blafarm Jul 05 '19 at 00:04
  • No failure logs TheMaster. But thanks. – blafarm Jul 05 '19 at 00:04

1 Answers1

1

The fix for this is to add another iframe along with the original in html:

<iframe 
  src="<url to the spreadsheet without the ?rm=minimal query>"
  style="visibility:hidden; position: absolute;"
>
</iframe>

Using Google Documents iframes in Web Applications have a lot of caveats, another one is that it resets scroll to top by each page refresh for example.

TheMaster
  • 45,448
  • 6
  • 62
  • 85