MrPea MrPea - 5 months ago 22
Javascript Question

Using a Google Web App - Can I pass a variable from one HTML page to another within the same web app

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...


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download