Phonegap - navigator.app.backHistory() 不适用于 HTML 后退按钮 [英] Phonegap - navigator.app.backHistory() not working on HTML back button

查看:27
本文介绍了Phonegap - navigator.app.backHistory() 不适用于 HTML 后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用的是 phonegap 2.6.对于后退按钮,我使用的是以下功能

In my app i am using phonegap 2.6.For back button, I am using the following function

document.addEventListener("backbutton", onBackKeyDown, false);

function onBackKeyDown() {
    alert("hello");
    navigator.app.backHistory();
}

document.addEventListener('deviceready', onDeviceReady, true);

上述功能当我点击设备的硬件后退按钮时工作正常.但是当我点击后退按钮时它不起作用.

The above function works fine when I click on the device's hardware back button. But when I click on the back button it is not working.

我设计的后退按钮如下:

I have designed my back button as below:

<a class="ui-link" href="#" rel="external" onclick="onBackKeyDown()">
        <img src="images/icon-back.png" alt="Phone" border="0">
</a>

但是这个按钮对于这个navigator.app.exitApp();(应用程序退出)工作正常.

But this button is working fine for this navigator.app.exitApp(); (application exit).

//Working Fine
function onBackKeyDown() {
    navigator.app.exitApp();
}

//Not Working
function onBackKeyDown() {
    navigator.app.backHistory();
}

但不适用于 navigator.app.backHistory();.

推荐答案

当我遇到同样的情况时,我尝试了 3 种不同的方法:

I have tried 3 separate things when I faced the same situation:

  • window.history.back()

navigator.app.backHistory();

History.go(-1);

单独来看,这些都不能解决问题.我把所有 3 件事放在一起,令我惊讶的是它奏效了.我真的不知道这背后是什么.

Individually, none of these solve the problem. I put all 3 things together and much to my surprise it worked. I really don't know what is behind it.

然后我减少到两个函数并删除:

Then I decreased to two functions and removed:

  • window.history.back()

现在我正在使用这个功能并且它工作正常.

Now I am using this function and it is working fine.

//Works Fine
function onBackKeyDown() {
    history.go(-1);
    navigator.app.backHistory();
}

这篇关于Phonegap - navigator.app.backHistory() 不适用于 HTML 后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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