访问被拒绝错误在Windows商店应用程序使用Javascript

Access is denied error in Windows Store App using Javascript

本文关键字:应用程序 Javascript Windows 拒绝 错误 访问      更新时间:2023-09-26

当有人试图关闭未保存的文件时,我试图在windows RT应用程序中启动保存对话框。然而,我一直得到一个0x80070005 - JavaScript runtime error: Access is denied错误

这是我用来启动消息对话框的代码。当"不保存"被选择(和BlankFile()运行)一切运行正常。然而,当你选择"保存文件",它抛出访问拒绝错误,当它试图运行.pickSaveFileAsync()

function createNewFile() 
{
    if (editedSinceSave)
    {
        // Create the message dialog and set its content 
        var msg = new Windows.UI.Popups.MessageDialog("Save this file?", 
            "Save Changes");
        // Add commands 
        msg.commands.append(new Windows.UI.Popups.UICommand("Don't Save", 
            function (command) {
                BlankFile();
            }));
        msg.commands.append(new Windows.UI.Popups.UICommand("Save File", 
            function (command) {
                //saveFile(true, true);
                testPop("test");
            }));
        // Set the command that will be invoked by default 
        msg.defaultCommandIndex = 2;
        // Show the message dialog 
        msg.showAsync();
    }
}
function testPop(text) {
    var msg = new Windows.UI.Popups.MessageDialog(text, "");
    msg.showAsync();
}

您的核心问题是您试图将一个消息对话框显示在另一个消息对话框之上。我在这里讨论细节和解决方案:在地铁应用程序中,"警报"的替代选项是什么?

然而,你的流程自然需要这发生——我建议考虑构建不同类型的流程,而不是堆叠对话框。

解决这个问题的方法似乎是设置一个命令id并在showAsync()done()函数中捕获它,如下所示

function createNewFile() 
{
    if (editedSinceSave)
    {
        // Add commands and set their CommandIds 
        msg.commands.append(new Windows.UI.Popups.UICommand("Dont Save", null, 1));
        msg.commands.append(new Windows.UI.Popups.UICommand("Save File", null, 2));
        // Set the command that will be invoked by default 
        msg.defaultCommandIndex = 1;
        // Show the message dialog 
        msg.showAsync().done(function (command) {
            if (command) {
                if (command.id == 1){
                    BlankFile();
                }
                else {
                    saveFile(true, true);
                }
            }
        });
    }
}

这不会抛出任何错误。我不知道为什么用另一种方式做会抛出错误,因为它似乎没有任何不同!