【问题标题】:Get previous page phonegap javascript获取上一页 phonegap javascript
【发布时间】:2013-05-16 09:57:48
【问题描述】:

如何在 phonegap 上使用 javascript 获取上一页?

只有当我来自一个特定的 html 文件时,我才想返回 (window.history.back()),否则我想在按下返回按钮时转到另一个 html 页面。 所以我想知道历史的上一页是哪一页。

我已经在谷歌上搜索了一段时间,但没有找到适合我的答案。

【问题讨论】:

    标签: javascript cordova html5-history


    【解决方案1】:

    如果你想要内置的东西,你可以使用document.referrer 来获取之前的 URL。但它可能不适合您的需求。更多信息hereherehere

    另一个非常简单的选择是将当前页面名称存储在会话存储中,读取它然后决定下一步做什么。

    //retrieve the previous page
    var previouspage = window.sessionStorage.getItem("page"):
    // if thee is no previous page you are on the first page
    if (previousPage == undefined){
     //do something if you want, this means it's the first page the user is seeing
     }
    //get current page address
    var currentPage = window.location.href;
    //store it
    window.sessionStorage.setItem("page",currentPage); 
    //check if the previous page is the one you wanted.
    if (previousPage == "the_page_you_wanted"){
     // do something.
     }
    

    LocalStorage vs SessionStorage

    【讨论】:

    • 谢谢,真的很有帮助,我也想过用localStorage,不过我觉得跟sessionStorage很像吧?
    • 这里不要使用本地存储。 LocalStorage 将在您的应用程序停止运行时存储您的数据,而 SessionStorage 将在您退出应用程序后被清除。这将防止您在用户关闭应用程序“the_page_you_wanted”时得到错误的结果。
    猜你喜欢
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2011-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多