最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to use localStorage in HTMLService? - Stack Overflow

programmeradmin0浏览0评论

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>

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>
Share Improve this question edited Apr 28, 2024 at 14:12 Wicket 38.4k9 gold badges78 silver badges193 bronze badges asked Sep 6, 2012 at 5:45 SrikanthSrikanth 83611 silver badges20 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 12

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>

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.

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

发布评论

评论列表(0)

  1. 暂无评论