Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 400
Srikanth Avatar asked Dec 26 '22 18:12

Srikanth


1 Answers

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>
like image 113
Buravchik Avatar answered Jan 11 '23 05:01

Buravchik