Srikanth
Srikanth

Reputation: 836

Is it possible to use localStorage in HTMLService?

Is it possible to use localStroage in HtmlService of Google Apps Script? I tried below code but it show error message as 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>

Upvotes: 4

Views: 2691

Answers (3)

Buravchik
Buravchik

Reputation: 529

Local storage is now supported in IFRAME sandbox mode:

function doGet() {
     return HtmlService.createHtmlOutputFromFile('Index')
        .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

<script>
    localStorage.setItem("mynote", "test msg");
    var note = localStorage.getItem("mynote");
    alert(note);
</script>

Upvotes: 12

Corey G
Corey G

Reputation: 7858

localStorage is not supported. It may be supported in the future, and an issue tracker feature request is appropriate.

Upvotes: -1

Srik
Srik

Reputation: 7957

localStorage is a part of HTML 5 which isn't supported by Apps Script. If you look at the documentation , it says Apps Script currently supports HTML 4.01.

However, you can open an enhancement request in the Issue Tracker to request for this feature.

As an alternative, you can use UserProperties or CacheService for your requirements.

Upvotes: -1

Related Questions