Javascript 是否在Chrome中设置/伪造/模拟window.external?

Javascript 是否在Chrome中设置/伪造/模拟window.external?,javascript,google-chrome,mocking,google-chrome-devtools,Javascript,Google Chrome,Mocking,Google Chrome Devtools,我正在制作一个使用window.external(稍后将在WPF WebBrowser控件中运行)的网站 但是,所有window.external方法都未定义,尽管我尝试了: window.external = { SetDragText: function() {}, ShowFileDialog: function() { onFileOpenCompleted(JSON.stringify(["D:\Temp\test.pdf"])) },

我正在制作一个使用window.external(稍后将在WPF WebBrowser控件中运行)的网站

但是,所有window.external方法都未定义,尽管我尝试了:

window.external = {
    SetDragText: function() {},
    ShowFileDialog: function() { 
        onFileOpenCompleted(JSON.stringify(["D:\Temp\test.pdf"])) 
    },
    OpenPdfViewer: function() {},
};

在Chrome debug/Dev Tools中是否有方法覆盖
window.external

这应该可以工作,您需要键入不带括号的函数来获取定义,否则您将调用它,它将返回undefined,因为您不返回任何内容

window.external={
SetDragText:函数(){},
ShowFileDialog:函数(){
onFileOpenCompleted(JSON.stringify([“D:\Temp\test.pdf”]))
},
OpenPdfViewer:function(){},
};
$(“#结果”).text(“实际函数定义:+String(window.external.SetDragText));
$(“#result2”).text(字符串(“函数调用结果:+window.external.SetDragText())



嗯,我刚才又查过了。它现在适合我了。然而,有时以后,
window.external
会再次返回到外部对象。我想我不知怎么得到了另一个
窗口
上下文或
外部
对象。抱歉,我发现了问题。这是Chrome新的调试覆盖功能问题。我的重写代码运行不一致。