保存的内容在本地存储中

发布于 2024-12-08 15:44:21 字数 181 浏览 0 评论 0原文

I want to save the content of the <a href> In the localstorage and reuse it. How can i do that? I want to keep the link working. I want to use it to link to webapps (user provided) and i want to achieve that with the localstorage (i am building an online os For personal(and maybe) public use it won't be as big like eyeos or jolicloud).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼睛会笑 2024-12-15 15:44:21

如果您想保存整个链接(包括属性):

<script>
function setLinks(){
     var all_links = document.getElementById("container").innerHTML;
     localStorage.setItem("savedLinkHTML", all_links);
}
function getLinks(){
    var all_links = localStorage.getItem("savedLinkHTML");
    if(all_links) document.getElementById("container").innerHTML = all_links;
}
window.onload = function(){
    getLinks();
}
window.onunload = function(){
    setLinks();
}
</script>
 ...
<div id="savedLinks"></div>

您可以创建自己的函数来动态添加更多链接(甚至图像)到容器中,这些链接在离开页面时自动保存,并在访问页面时再次显示。

另请参阅:https://developer.mozilla.org/en/DOM/Storage

If you want to save the whole link (including attributes):

<script>
function setLinks(){
     var all_links = document.getElementById("container").innerHTML;
     localStorage.setItem("savedLinkHTML", all_links);
}
function getLinks(){
    var all_links = localStorage.getItem("savedLinkHTML");
    if(all_links) document.getElementById("container").innerHTML = all_links;
}
window.onload = function(){
    getLinks();
}
window.onunload = function(){
    setLinks();
}
</script>
 ...
<div id="savedLinks"></div>

You can create your own functions to dynamically add more links (even images) to the container, which are automatically saved when leaving the page, and shown again when visiting the page.

See also: https://developer.mozilla.org/en/DOM/Storage

时光沙漏 2024-12-15 15:44:21

为什么不直接获取 URL

var url = window.location.href;

,然后将其存储在 key(i) 的值中呢?我知道这听起来太简单了,但这就是您要问的......不是吗?您只需要一个用于检索的命名系统。

Why not just grab the URL

var url = window.location.href;

and then store it in the value for key(i)? I know that sounds too simple, but that is what you are asking... isn't it? You would just need a naming system for retrieval.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文