Can HTMLService support the usage of localStorage?

Can we utilize localStorage in the HtmlService of Google Apps Script? I attempted the code below but encountered an error message stating that localStorage is not defined.

function doGet() {
  var ui = HtmlService.createHtmlOutputFromFile('main');
  return ui;
}

<!DOCTYPE html>
<html>
  <head>
    <script>localStorage.setItem('howGood', 'awesome');</script>
  </head>
<body>
  </body>
</html>

Answer №1

Now you can use local storage in IFRAME sandbox mode:

function displayContent() {
     return HtmlService.createHtmlOutputFromFile('Homepage')
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

<script>
    localStorage.setItem("mydata", "hello world");
    var data = localStorage.getItem("mydata");
    alert(data);
</script>

Answer №2

Local storage is a feature of HTML 5 that is not currently supported by Apps Script. The documentation states that Apps Script only supports HTML 4.01 at the moment.

If you need this feature, you can submit an enhancement request on the Issue Tracker.

In the meantime, you have the option to use UserProperties or CacheService for your needs.

Answer №3

At the current moment, localStorage is not compatible. However, there is a possibility of it being supported in upcoming updates. You can also submit a feature request through the issue tracker for further consideration.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the joy of reading with wrap/unwrap to consume more content in less

I am experimenting with a 'read-more read-less' feature using a wrap method that currently only works for the 'show more' functionality. So, to clarify, if the text exceeds a certain length, I truncate it and insert a read-more-link ( ...

Looking to incorporate HTML5 videos into a responsive Bootstrap carousel?

I've been working on creating a carousel that includes videos. When it comes to images, everything works smoothly as they are responsive even in mobile view. However, I'm encountering an issue with videos where the width is responsive but the hei ...

Unable to modify the appearance of text on the canvas

Trying to customize the font style of canvas text with Press Start 2P The URL has been imported into a CSS file as follows: @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); .canvasClass{ font-family: ...

Retrieve information using the useEffect hook on a server-side rendered webpage

I am currently working on a project using React JS and Next JS. The page is dynamic, utilizing getStaticPaths and getStaticProps to fetch most data on the server side for rendering. However, there are certain pieces of data that require a token stored in l ...

My react-native app is having trouble with modal closure

As I develop an app, I encounter an issue with Modal usage across different screens. I have created a universal component for handling all Modals. By passing JSX and toggling visibility based on a Global variable, the problem arises when switching screens. ...

Automatically press a button that appears on the webpage

I am looking to automate the clicking of a button that appears on a website. How can I accomplish this using Python? I have no experience in JavaScript and am fairly new to programming. Here is the outer HTML code for the button: <button type="button" ...

Unfortunately, CSS3 PIE is not compatible with border-radius and box-shadow properties

I created a basic HTML/CSS code for testing purposes, but I'm having trouble getting the library to function properly. I've placed the .htc, .php and .js files in the same directory as index.html, but it just won't work. Check out the code ...

Pressing the Enter key does not initiate a redirect on the page

Hey there! I've set up a text field where users need to input a password in order to download a PDF file. If the password is correct, they are directed to the URL of the PDF file. However, if the password is wrong, they are redirected to a page called ...

loop through the links using their unique identifiers

Here is my current code in Jade/Pug: #pm_language.dropdown(aria-haspopup='true', aria-expanded='false') button#langbutton.btn.btn-primary.dropdown-toggle(type='button', data-toggle='dropdown') Lang [RU] ...

Guide to changing markers on zoom change using google maps API

Looking to customize the marker image on a map when zoom level exceeds 5. I can detect zoom changes, but unsure how to update the image. ...

What is the best way to pass an array from a controller to an AJAX function in Laravel 4?

Hi there, I'm currently using Laravel 4 and I'm still a beginner in this field. I am trying to retrieve an array of data from my controller to pass it to my AJAX function for assisting me in creating my chart. Here is the code snippet from my co ...

Disabling GPS with HTML5/phonegap: A step-by-step guide

Looking to create a function that can toggle GPS on and off for both iPhone and Android devices ...

Activate the Vue checkbox option

Starting out with Vue and web development. I am currently building my app using Laravel and Vue. This is the code snippet I am working on: created: function () { let self = this; self.setActive('tab1'); axios.get(this.$apiAdress + '/api/tas ...

Prevent side menu from automatically hiding when clicking on the heading

My menu is set up with headings and subheadings. When I click on the headings, it expands to display the corresponding subheadings, but it automatically collapses when clicking on the headings. I want it to stay expanded when clicking on the headings. He ...

Switching class names on click in Vue.js

When clicked, I would like to toggle the class name from "product fav" to "product fav active". The change should be conditional; if the class is already active, it should be removed. ...

What is the method to have the text cursor within a text field start a few pixels in?

I need a text field with the cursor starting a few pixels (let's say 4) from the left-hand side. I am aware that this can be achieved by adjusting the size of the text field using padding, but I am curious if there is a way to resize the text box with ...

determining the preference between setTimeout and setImmediate

After reading the documentation on the node, it mentions: setImmediate(callback, [arg], [...]) This function is supposed to execute callback immediately after I/O events callbacks and before setTimeout and setInterval However, in practice, I noticed tha ...

Guide to creating a search-enabled dropdown menu

Recently, I created a dropdown menu using Bootstrap. The code I used can be found here: http://getbootstrap.com/docs/4.0/components/dropdowns/ <div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownM ...

Improved Node.js algorithm designed to identify anagrams of a specific string in an array. The approach must not rely on generating all possible subsets to find the anagram of the string

I am looking to create a collection of anagram pairs within an array. The input will consist of the initial array of strings. For example: let inputArray = ["abcd", "dbac", "adfs", "adsf", "bDca"]; This program should consider the case of the letters, m ...

Dependencies in Scala.js for CSS styling

I am currently having an issue implementing Scala.js with the bootstrap library. Including the js file was a simple and straightforward process: jsDependencies +="org.webjars" % "bootstrap" % "3.3.7-1" / "bootstrap.js" minified "bootstrap.min.js" However ...