简体   繁体   English

有没有办法区分我的Javascript在基于三叉戟的应用程序和Internet Explorer中运行?

[英]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. Chrome提供的chrome对象具有一些不同的属性,具体取决于环境。 Anyone know of anything similar for IE? 任何人都知道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 . 检查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为null,则将Web页面加载到Web Component中,否则通过浏览器加载。

window.external enable you to communicate with [ComVisible(true)] instances which are enabled by default in the browsers. window.external使您能够与浏览器中默认启用的[ComVisible(true)]实例进行通信。 As long as your apps are not decorated with [ComVisible(true)] , you can distinguish between app and browser page consumption. 只要您的应用程序没有使用[ComVisible(true)]进行修饰,您就可以区分应用程序和浏览器页面消耗。

The way Google Analytics checks for browser and device is the HTTP User-Agent header. Google Analytics检查浏览器和设备的方式是HTTP User-Agent标头。 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://jonathanstark.com/blog/windows-phone-8-user-agent-string

http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx 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 您也可以在Javascript中解析此字符串: 使用JavaScript获取用户代理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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