简体   繁体   English

从主屏幕重新打开支持ios Web应用程序的页面时,方法会保留新的dom元素

[英]methods keep to new dom elements when re-opening ios web-app-capable page from home screen

I've made html web page using jquery to add and change elements in the dom. 我已经使用jquery制作了html网页来添加和更改dom中的元素。

I'm using this meta tag to open the page full screen when launched from home screen. 从主屏幕启动时,我正在使用此meta标签全屏打开页面。 To emulate a basic app like experience. 模拟像体验这样的基本应用程序。

<meta name="apple-mobile-web-app-capable" content="yes">

I've used manifest files before when creating a web-app-capable page to store files on the device, but these are files that cant be updated right? 在创建具有Web应用程序功能的页面以在设备上存储文件之前,我曾使用过清单文件,但是这些文件无法更新吗?

My page is javascript based, i'm intrigued if there is way that I can store the page dom contents somehow. 我的页面是基于javascript的,如果我可以某种方式存储页面dom的内容,我很感兴趣。 Idea being is that when the web page is re-opened from the home screen or home button double click method, it shows the last state page contents, rather that reloading the page from scratch. 想法是,当从主屏幕或主页按钮双击方法重新打开网页时,它将显示最后一个状态页面的内容,而不是从头开始重新加载页面。

Can this be achieved using a cookie or something? 可以使用cookie或其他东西来实现吗?

Any ideas or pointers would be great thanks. 任何想法或指针将非常感谢。

I ended up using local storage. 我最终使用了本地存储。

var data = localStorage.getItem('my_data');

// for testing
alert(data);

set_data = function() {

  data = localStorage.setItem('my_data', 'whatever');

  // for testing
  alert(localStorage.getItem('my_data'));

}

delete_data = function() {

  data = localStorage.clear();

  // for testing
  alert(localStorage.getItem('my_data'));

}

See working jsfiddle https://jsfiddle.net/joshmoto/j2y8o6rq/ 参见工作jsfiddle https://jsfiddle.net/joshmoto/j2y8o6rq/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM