繁体   English   中英

Windows Phone 7后退按钮通过Java处理

[英]Windows Phone 7 Back Button Handling through Javascript

我想知道当我们通过javascript按下Win Phone 7的后退按钮时如何执行事件。

document.addEventListener("deviceready", onDeviceReady, false);


function onDeviceReady() {
            document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
//want to redirect a particular page.?? want to handle functioning of back button
}

请尝试以下操作:

<!DOCTYPE html>
<html>
  <head>
    <title>gaurish's Cordova Back Button Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Call onDeviceReady when Cordova is loaded.
    //
    // At this point, the document has loaded but cordova-2.0.0.js has not.
    // When Cordova is loaded and talking with the native device,
    // it will call the event `deviceready`.
    //
    function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // Cordova is loaded and it is now safe to call Cordova methods
    //
    function onDeviceReady() {
        // Register the event listener
        document.addEventListener("backbutton", onBackKeyDown, false);
    }

    // Handle the back button
    //
    function onBackKeyDown() {
    }

    </script>
  </head>
  <body onload="onLoad()">
  </body>
</html>

现在,测试一下

  1. 将一些代码添加到要运行的onBackKeyDown()中,例如

    function onBackKeyDown() { currentId = $.mobile.activePage.attr('id'); if(currentId == "#swipediv"){ $.mobile.changePage("#home", "slide", false, true); } else{ history.go(-1); } }

  2. 加载cordova-2.0.0.js

  3. 重新访问WP7 PhoneGap Backbutton支持
  4. 阅读文档

如果仍然无法解决问题,请提交错误报告

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM