【问题标题】:how to store path name value in local storage or cookie如何将路径名值存储在本地存储或 cookie 中
【发布时间】:2018-02-06 12:52:15
【问题描述】:

我有 angular 应用程序,并且基于以前的路径名而不是页面名,我想将值存储在 cookie 或本地存储中

首页的路径名是/content/drive.html/find-drive
第二页的路径名是/content/drive.html/drive-results

当我在第二页时,我想在 cookie 中存储 find-drive

同样

首页的路径名是/content/drive.html/find-drive-advanced
第二页的路径名是/content/drive.html/drive-results

当我在第二页时,我想将上一个路径位置存储在我的 cookie 或本地存储中。对于这种情况,我想存储“find-drive-advanced”

注意:document.referrer 不起作用,window.parent.URl 不起作用

【问题讨论】:

标签: javascript jquery cookies local-storage


【解决方案1】:

使用localStorage

url1 = '/content/drive.html/find-drive'url2 = '/content/drive.html/drive-results'

像这样保存它们:

localStorage.setItem('url1', url1);
localStorage.setItem('url2', url2);

要检索值,只需编写

var url1 = localStorage.getItem('url1');

【讨论】:

    猜你喜欢
    • 2017-09-19
    • 2019-10-26
    • 2012-05-31
    • 2015-09-05
    • 2021-10-08
    • 2019-06-12
    • 2018-02-18
    • 2017-06-23
    • 2020-12-26
    相关资源
    最近更新 更多