我和科多瓦一起开发了一个混合应用程序。这个应用程序非常简单,所以我没有使用框架。几乎所有页面都是使用jQuery的ajax()
方法通过Ajax注入的,然后使用HTML5历史API通过pushState()
方法添加到历史记录中。
为了让用户回到以前访问过的页面(历史上的一个页面),我创建了一个按钮。我侦听backbutton
事件,并点击该按钮,当事件被触发时,我执行以下处理程序:
onBackButton: function() {
window.history.length === 0 ? navigator.app.exitApp() : window.history.back();
}
为了确保最大程度的兼容性,我还将history.js添加到项目中。
它在安卓和Mac上的iOS模拟器上都很有魅力,但在真正的设备上却不起作用。所发生的是iOS捕获事件,但是方法的执行不会改变页面。我已经在StackOverflow上尝试过几种基于以前答案的方法,但没有成功。一些例子是:history.back()在phonegap构建中不工作和Phonegap按钮不工作的navigator.app.backHistory()。
我能尝试什么?
发布于 2014-07-02 14:43:17
几个月前看到这个答案了吗?显然,iOS在仅通过脚本导航历史记录时存在一些安全问题。这里的答案还包括通过散列URL:StackOverflow问题所做的工作。
发布于 2014-07-02 08:50:25
你可以简单地使用,
history.go(-1);
向后航行。
发布于 2014-07-02 03:38:07
试试这个。
main.js
var pagesHistory = [];
var currentPage = {};
var path = "";
page1.js
currentPage = {};
currentPage.back = function() {
pagesHistory.pop();
};
currentPage.loadPage2 = function() {
pagesHistory.push(path + "pages/Page2.html");
};
page2.js
currentPage = {};
currentPage.back = function() {
pagesHistory.pop();
};
currentPage.loadPage1 = function() {
pagesHistory.push(path + "pages/Page1.html");
};
参考资料:http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v620/BuildingMultiPageApplicationProject.zip
https://stackoverflow.com/questions/24352757
复制相似问题