Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to distinguish that my Javascript is running in a trident-based application vs. Internet Explorer?

I've got a third party script that runs in many places on the web. I'd like to be able to tell when I'm running in an app vs. a browser. The user agent doesn't always help. Chrome provides the chrome object which has some different properties depending on the environment. Anyone know of anything similar for IE?

This is for a product similar to google analytics which can be implemented or wind up in many environments, and I'm trying to distinguish them better.

like image 784
sprugman Avatar asked Feb 26 '14 20:02

sprugman


1 Answers

Check for window.external. If window.external is null then the web page is loaded into a Web Component, otherwise it is loaded via browser.

window.external enable you to communicate with [ComVisible(true)] instances which are enabled by default in the browsers. As long as your apps are not decorated with [ComVisible(true)], you can distinguish between app and browser page consumption.

  • Read more about window.external on http://msdn.microsoft.com/en-us/library/ie/ms535246%28v=vs.85%29.aspx
like image 90
Marjan Nikolovski Avatar answered Nov 12 '22 05:11

Marjan Nikolovski