Mon*_*ica 1 javascript html5-history cordova
如何在phonegap上使用javascript获取上一页?
我想返回(window.history.back())只有当我来自一个特定的html文件时,否则我想在按下后退按钮时转到另一个html页面.所以我想知道哪一个是历史的前一页.
我已经谷歌搜索了一段时间,我没有找到适合我的答案.
如果您想要内置的内容,可以使用它document.referrer来获取以前的URL.但它可能不适合您的需求.更多信息在这里,这里和这里
另一个非常简单的选择是将当前页面名称存储在会话存储中,读取它然后决定下一步该做什么.
//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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5104 次 |
| 最近记录: |