Correct Condition For Window.External.Notify is Defined

与世无争的帅哥 提交于 2020-03-03 09:09:29

问题


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)

回答1:


You can use this:

if (typeof (window.external) !== 'undefined' && ('notify' in window.external)) {
....
}

For reasons only known to Microsoft, window.external.notify is undefined even though you can make calls to it without any issues.



来源:https://stackoverflow.com/questions/41057092/correct-condition-for-window-external-notify-is-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!