问题
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