Windows Phone 8 - Javascript : back button

眉间皱痕 提交于 2019-12-22 18:29:11

问题


I need to handle the back button in HTML 5 - Javascript application for Windows Phone 8. I found a lot of solutions in C# but no one in Javascript. Does anybody know how to do this ?


回答1:


//Hardware back button could be handle using this.

 var hardwareButtons = Windows.Phone.UI.Input.HardwareButtons;
    hardwareButtons.addEventListener("backpressed", function (e) {
      e.handled = true; //handle back button event(won't close the app).
      history.back(); //go back to history
    });



回答2:


Here is my code that work on windows phone 7 & 8

//WPback button handler methods
$(document).ready(function()
{
document.addEventListener("deviceready", setOverrideBackbutton, false);
});

function setOverrideBackbutton()
{
document.addEventListener("backbutton", backButtonTap, true);
}

/**
 * Callback after a backbutton tap on windows platforms.
 * Do nothing.
 */
function backButtonTap()
{
//Do not remove
}



回答3:


If you're using PhoneGap, have a look at http://www.risingj.com/archives/493



来源:https://stackoverflow.com/questions/17090346/windows-phone-8-javascript-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!