[英]Actionscript 3, flex: How to find out which is browser you are currently in?
I need to detect via AS3 inside flex mxml appication which is browser I am in - FF, Chrome, IE etc, only name and version.我需要通过 flex mxml 应用程序中的 AS3 检测我所在的浏览器 - FF、Chrome、IE 等,只有名称和版本。 How to do such thing?
怎么做这样的事情?
Yes, you're going to use javascript, but you dont actually need to put javascript in the page.是的,您将使用 javascript,但实际上您不需要将 javascript 放在页面中。
Here's a quick script example of getting that information from your flex app without adding anything to the containing html page:这是一个快速脚本示例,它从您的 flex 应用程序获取该信息,而不向包含的 html 页面添加任何内容:
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function creationCompleteHandler(event:FlexEvent):void
{
var appName : String = String(ExternalInterface.call("function(){return navigator.appName}"));
var appVersion : String = String(ExternalInterface.call("function(){return navigator.appVersion}"));
var userAgent : String = String(ExternalInterface.call("function(){return navigator.userAgent}"));
trace( appName ) ;
trace( appVersion );
trace( userAgent );
}
]]>
</fx:Script>
This traces the info out to the console, so for example when I run it I get:这会将信息追踪到控制台,因此例如当我运行它时,我得到:
Microsoft Internet Explorer
4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; GTB6.6; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Let me know if you have any issues!如果您有任何问题,请告诉我!
It's not tricky if you use some client side JavaScript and the ExternalInterface class in the Flash library.如果您在 Flash 库中使用某些客户端 JavaScript 和 ExternalInterface class ,这并不难。
Here's a brief tutorial on doing that: http://codingrecipes.com/calling-a-javascript-function-from-actionscript-3-flash这是一个简短的教程: http://codingrecipes.com/calling-a-javascript-function-from-actionscript-3-flash
Your JS would need to run a browser client check.您的 JS 需要运行浏览器客户端检查。
As per my research navigator.appName
will return string Netscape
for browsers like: IE11, Firefox, Chrome and Safari.根据我的研究,
navigator.appName
将为浏览器返回字符串Netscape
,例如:IE11、Firefox、Chrome 和 Safari。 check this.检查这个。
If you want to detect browser name try this:如果你想检测浏览器名称试试这个:
var browserName:String;
var userAgent:Object = ExternalInterface.call("window.navigator.userAgent.toString");
if(userAgent.toLowerCase().indexOf("chrome") !== -1)
{
browserName = "Chrome";
}
if(userAgent.toLowerCase().indexOf("mozilla") !== -1)
{
browserName = "Mozilla";
}
if(userAgent.toLowerCase().indexOf("safari") !== -1)
{
browserName = "Safari";
}
reference: check visitor OS & Browser using as3参考: 使用 as3 检查访问者操作系统和浏览器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.