如何在警报框中使用 history.go(-1) Javascript,通过 phonegap 构建 jQuery 移动

How to use history.go(-1) Javascript when used in alert box for a jQuery mobile app build via phonegap

本文关键字:Javascript 通过 phonegap 移动 jQuery 构建 go history      更新时间:2023-09-26

实际上,我正在尝试检查互联网连接,如果没有可用的互联网连接,那么我会弹出一个警告框,显示抱歉,无法显示数据,当用户按下确定按钮时,我想将他传输回我的应用程序的主页。

我目前的Javascript函数如下,但它没有按预期工作。

   function showerror(){
      alert("Sorry, Check your Internet Connection. Going Back to the Home page. showerror()");   
      history.go(-1);
      }

请任何帮助不胜感激。

应使用 navigator.notification.alert 方法在对话框关闭时显示带有回调的设备特定警报。然后使用history.back()将用户发送到上一页。

http://docs.phonegap.com/en/1.8.1/cordova_notification_notification.md.html#notification.alert

例:

function showerror() {
  navigator.notification.alert(
    'Sorry, Check your Internet Connection. Going Back to the Home page. showerror()',
    function() {
      history.back();
    }
  );
}

编辑:

如果您知道要返回的特定页面,则始终可以使用$.mobile.changePage转到该页面。唯一的问题是在带有后退按钮的设备(Android,WP7)上运行时。

例:

function showerror() {
  navigator.notification.alert(
    'Sorry, Check your Internet Connection. Going Back to the Home page. showerror()',
    function() {
      $.mobile.changePage('#homePage');
    }
  );
}