首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cordova windows 10在软件关闭按钮/ alt+F4上添加确认消息

Cordova windows 10在软件关闭按钮/ alt+F4上添加确认消息
EN

Stack Overflow用户
提问于 2017-10-19 14:16:58
回答 1查看 464关注 0票数 0

当用户单击运行在windows 10 (桌面)上的Cordova应用程序的软件关闭按钮(X / Alt+F4)时,如何显示确认消息。我试过几件事,但都没有用:

代码语言:javascript
复制
//This only fire when clicking on the back arrow.
document.addEventListener("backbutton", onBackKeyDown.bind(this), false); 
function onBackKeyDown(e) {
    navigator.notification.alert('onBackKeyDown');
}

//This fire but to late and cannot cancel or display message
document.addEventListener( 'pause', onPause.bind( this ), false );
function onPause() {
    debugger;
    navigator.notification.alert('onPause');
};

//This is never fired
WinJS.Application.addEventListener("unload", unloadEv);
function unloadEv(ev) {
    navigator.notification.alert('unloadEv');
}

//This is never fired
window.onbeforeunload = onbeforeunload;
function onbeforeunload(evt) {
    navigator.notification.alert('onbeforeunload');
}

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-18 09:26:51

步骤: 1

关闭按钮是限制功能功能,以启用

打开package.windows10.appxmanifest上的platform -> windows文件夹。

步骤: 2

在xml包标记中,应该如下所示

<Package IgnorableNamespaces="uap mp rescap" xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10">

在功能标签中添加<rescap:Capability Name="confirmAppClose" />

<Capabilities> <rescap:Capability Name="confirmAppClose" /> </Capabilities>

在这里,xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapaIgnorableNamespaces="rescap"支持受限的功能。

步骤: 3

并在js文件中添加以下javascript代码并构建

代码语言:javascript
复制
 Windows.UI.Core.Preview.SystemNavigationManagerPreview.getForCurrentView().oncloserequested = function (args) {
            args.detail[0].handled = true;
            var message = new Windows.UI.Popups.MessageDialog("Details is not Saved Do you want save or exit the application..?");
            message.commands.append(new Windows.UI.Popups.UICommand("Save", SaveHandler));
            message.commands.append(new Windows.UI.Popups.UICommand("Exit", UnsaveHandler));
            message.commands.append(new Windows.UI.Popups.UICommand("Cancel", CancelHandler));
            message.showAsync();
        }
        function SaveHandler(command) {
                //save button
        }
        function CancelHandler(command){
            return false;
        }
        function UnsaveHandler(command) {
            window.close();
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46832073

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档