【问题标题】:How to save the url in a cookie then open the url from the cookie [closed]如何将 url 保存在 cookie 中,然后从 cookie 中打开 url [关闭]
【发布时间】:2017-01-11 12:15:31
【问题描述】:

如何创建 2 个按钮。一个“保存此页面”,第二个“打开保存的页面”按钮。 “保存此页面”按钮将存储该页面的当前 url。同时,“打开保存的页面”按钮会将用户重定向回保存此页面。

提前致谢!

【问题讨论】:

标签: javascript jquery session redirect cookies


【解决方案1】:

您可以尝试以下方法:

$(document).on('click', '[save page button class]', function () {
    $.cookie("SavedPageURL", "(Your URL here)");
});

$(document).on('click', '[open saved page button class]', function () {
    window.location.href = $.cookie("SavedPageURL");
});

您需要为此包含 jquery cookie js 文件。

【讨论】:

  • 这段代码有什么问题吗??
  • 谢谢Himanshu Vohra,我必须把这段代码放在两个页面上吗?
  • @lien 您需要将第一次点击事件放在您想要将 URL 保存到 cookie 的页面上,并将第二次点击事件放在您想要重定向到其他页面的页面上。
  • 不确定您的评论为何被否决。你答对了。谢谢老哥!
  • 顺便说一句,它适用于github.com/carhartl/jquery-cookie,但不适用于此github.com/js-cookie/js-cookie。你知道为什么吗?
猜你喜欢
  • 2012-04-07
  • 1970-01-01
  • 1970-01-01
  • 2016-04-28
  • 2021-06-13
  • 1970-01-01
  • 2019-10-25
  • 2022-12-16
  • 2011-04-27
相关资源
最近更新 更多