I am building an UWP app with JavaScript. Currently clicking the Back Button closes the app. However, I want it to call a JavaScript function.
It'd be great if anyone can share the code for Creating a Windows Runtime component and calling it from JavaScript to handle the Back Button press.
var systemNavManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
function startApp(){
// backRequested event
if (systemNavManager !== null) {
systemNavManager.addEventListener("backrequested", backRequested, false);
}
}
function backRequested() {
if (window.location.href.indexOf("/default.html") === -1) { // not on home page, go back
// nav back
window.history.back();
}
}
Source: https://github.com/Microsoft/TVHelpers/blob/master/WinRTjs/BackBtnTitleBarCustomization/js/main.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.