Tugrul Emre Atalay
Tugrul Emre Atalay

Reputation: 938

Correct Condition For Window.External.Notify is Defined

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)

Upvotes: 1

Views: 1564

Answers (1)

Marlon
Marlon

Reputation: 2139

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.

Upvotes: 6

Related Questions