2012-07-30 94 views
0

处理我想知道如何当我们打通过JavaScript赢手机7后退按钮就可以进行事件..Windows Phone 7的后退按钮通过JavaScript

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 
} 
+1

如果有可能,我不知道它是什么,这将是一个令人难以置信的烦人的功能,并保证大多数用户永远不会返回到您的网站/应用程序。 – jbabey 2012-07-30 13:03:02

回答

1

尝试以下操作:

<!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. Loadup cordova-2.0.0.js

  3. 结账WP7 PhoneGap Backbutton Support Re-visited
  4. 阅读documentation

如果这仍然不起作用,提交bug report