【发布时间】:2013-05-16 09:57:48
【问题描述】:
如何在 phonegap 上使用 javascript 获取上一页?
只有当我来自一个特定的 html 文件时,我才想返回 (window.history.back()),否则我想在按下返回按钮时转到另一个 html 页面。
所以我想知道历史的上一页是哪一页。
我已经在谷歌上搜索了一段时间,但没有找到适合我的答案。
【问题讨论】:
标签: javascript cordova html5-history
如何在 phonegap 上使用 javascript 获取上一页?
只有当我来自一个特定的 html 文件时,我才想返回 (window.history.back()),否则我想在按下返回按钮时转到另一个 html 页面。
所以我想知道历史的上一页是哪一页。
我已经在谷歌上搜索了一段时间,但没有找到适合我的答案。
【问题讨论】:
标签: javascript cordova html5-history
如果你想要内置的东西,你可以使用document.referrer 来获取之前的 URL。但它可能不适合您的需求。更多信息here、here 和 here
另一个非常简单的选择是将当前页面名称存储在会话存储中,读取它然后决定下一步做什么。
//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.
}
【讨论】: