[英]How to handle back button of an UWP app with Javascript?
I am building an UWP app with JavaScript. 我正在使用JavaScript构建UWP应用。 Currently clicking the Back Button closes the app.
当前,单击“后退”按钮将关闭应用程序。 However, I want it to call a JavaScript function.
但是,我希望它调用JavaScript函数。
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. 如果任何人都可以共享用于创建Windows运行时组件并从JavaScript调用以处理“后退按钮”按下操作的代码,那将是很好的。
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 来源: https : //github.com/Microsoft/TVHelpers/blob/master/WinRTjs/BackBtnTitleBarCustomization/js/main.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.