How can I use `localStorage` to store an entire page?

前端 未结 2 1548
没有蜡笔的小新
没有蜡笔的小新 2021-02-06 14:09

I\'ve been reading the book HTML in action and in chapter 5, it shows how to create a mobile application that can be run offline. My only doubt is: can I do this for an

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 14:20

    For example you can use localStorage for saving variable:

    // Store
    localStorage.setItem("lastname", "Smith");
    // Retrieve
    document.getElementById("result").innerHTML = localStorage.getItem("lastname");
    

    and get it after:

    localStorage.getItem('lastname');
    

    window.localStorage implemented follow interface which accepted by W3C:

    interface Storage {
      readonly attribute unsigned long length;
      [IndexGetter] DOMString key(in unsigned long index);
      [NameGetter] DOMString getItem(in DOMString key);
      [NameSetter] void setItem(in DOMString key, in DOMString data);
      [NameDeleter] void removeItem(in DOMString key);
      void clear();
    };
    

    More information you can read here

提交回复
热议问题