简体   繁体   中英

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.

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.

The way Google Analytics checks for browser and device is the HTTP User-Agent header. It lets you check for browser, browser version, OS, OS version, and sometimes device:

http://jonathanstark.com/blog/windows-phone-8-user-agent-string

http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx

You can parse this string in Javascript as well: Getting the User Agent with JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM