0

I have created a Google Web App. It has 2 HTML pages that I can switch between using the principles described in this answer from Stack Overflow

Linking to another HTML page in Google Apps Script

The first HTML page calls a server side function. It returns data from a Google spreadsheet and assigns the data to a variable.

When a user switches to HTML page 2 the variable is lost and so when switching back to page 1 the script must call the server side function again, which takes a few seconds.

Is it possible to maintain the variable for the full session?

I've tried assigning it as as a global variable in the HTML files, as a global var in the .gs file, and passing it as a parameter in the URL but none of these seem to work.

I suspect it's not possible due to the nature of the apps script HTML service but you never know...

thanks

MrPea
  • 605
  • 6
  • 18

1 Answers1

0

You could store the variable using the WebStorage API.


If storage capacity is an issue then I would recommend using IndexedDB. Its a NoSQL database built into most modern browsers. The API can be a bit complex to handle so you may want to leverage a framework like Dexie

TheAddonDepot
  • 7,422
  • 2
  • 15
  • 24