获取上一页phonegap javascript [英] Get previous page phonegap javascript

查看:73
本文介绍了获取上一页phonegap javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I get the previous page with javascript on phonegap?

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

I want to go back (window.history.back()) only if I come from one specific html file, otherwise I want to go to another html page when back button is pressed. So I want to know which one is the previous page on history.

我已经搜索了一段时间,但没有找到适合我的答案.

I have been googling for a while and I didn't find an answer that suits for me.

推荐答案

如果您希望内置某些内容,可以使用document.referrer来获取先前的URL.但这可能无法满足您的需求.更多信息此处这里

If you want something built in you can use document.referrer to get the previous URL. But it might not be reliable for your needs. More info here, here and here

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

Another VERY simple option is to store the current page name in the session storage, read it and then decide what to do next.

//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与SessionStorage

这篇关于获取上一页phonegap javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆