PhoneGap的 - navigator.app.backHistory()不工作的HTML后退按钮 [英] Phonegap - navigator.app.backHistory() not working on HTML back button

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

问题描述

在我的应用程序,我使用PhoneGap的2.6.For后退按钮,我使用下面的函数

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(); (应用程序退出)

//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天全站免登陆