问题描述
我正在开发需要在javascript中调用window.external.notify的混合应用程序,但是此js代码也应在浏览器中运行.因此我们必须要有一个条件来检测window.external.notify是已定义还是未定义.因此我们使用该代码,但在运行时window.external.notify中显示其值类似于{...}(但无法打开).有什么办法可以解决吗?
I'm developing hybrid application that require to call window.external.notify in javascript but this js code should run in browser also. So we have to have a condition for detecting is window.external.notify is defined or undefined. So we use that code but in runtime window.external.notify shows its value is like that {...} (but can't open). Are there any way to handle it?
if(window.external !== undefined && window.external.notify !== undefined)
推荐答案
您可以使用此
if (typeof (window.external) !== 'undefined' && ('notify' in window.external)) {
....
}
由于仅Microsoft知道的原因,即使您可以毫无问题地调用window.external.notify
,它也是undefined
.
For reasons only known to Microsoft, window.external.notify
is undefined
even though you can make calls to it without any issues.
这篇关于定义了Window.External.Notify的正确条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!