刷新后保留网页的更改 [英] Keep the changes of a web page after refresh
问题描述
我最近开发了一个脚本来突出显示基于 document.execCommand()
的网页中的文本,但是如果我刷新我的网页,则更改将会消失。
I recently developed a script to highlight text in a web page based on document.execCommand()
but the changes are gone if I refresh my web page.
如何为每个用户保留更改?
How can I keep the change for every user ?
推荐答案
由于我不确定你实际想要坚持什么,我会提供一些通用信息。
As I am rather unsure what you actually want to persist I will give some generic information.
有关存储的 DiveIntoHtml5 的一些好读物。
Some good reading at DiveIntoHtml5 on storage.
我建议现在看一下 sessionStorage
或 localStorage
通常作为 HTML5
,浏览器支持要大得多。
I would suggest taking a look at either sessionStorage
or localStorage
now while these are regarded generally as HTML5
the browser support is much greater.
您可以在 keyValueStorage 的支持-storagerel =nofollow> CanIUse
You can see the support of keyValueStorage
at CanIUse
您可以按如下方式存储键/值对:
You can store a key / value pair as follows:
localStorage.setItem("key", "value");
然后您可以按如下方式检索该值:
You can then retrieve the value as follows:
localStorage.getItem("key");
删除:
localStorage.removeItem("key");
sessionStorage
与上述相同,但会仅在浏览器打开时保持不变。它持续存在于浏览器的会话中。但是 localStorage
将一直存在,直到通过代码或清除浏览器将其删除。
sessionStorage
works the same as above but will only persist while the browser is open. It persists for the "session" of the browser. However localStorage
will persist until it is removed by code or by clearing the browser.
这篇关于刷新后保留网页的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!