简体   繁体   English

如何在Flex中获取有关用户浏览器的信息?

[英]How do I get information about the User's Browser in Flex?

I'd like to know what Browser the User is using to view my Flex application. 我想知道用户使用什么浏览器来查看我的Flex应用程序。 How can I get at the User Agent string and other information? 如何获取用户代理字符串和其他信息?

you can 'embed' your javascript inside AS3 code like this : 你可以在AS3代码中'嵌入'你的javascript,如下所示:

var v : String = ExternalInterface.call("function(){return navigator.appVersion+'-'+navigator.appName;}");
var t : TextField = new TextField();
t.autoSize = TextFieldAutoSize.LEFT;            
addChild(t);
t.text = v;

the textField will display infos about the navigator like this (chrome): textField将显示关于导航器的信息(chrome):

5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19-Netscape 5.0(Windows; U; Windows NT 5.1; en-US)AppleWebKit / 525.19(KHTML,如Gecko)Chrome / 1.0.154.53 Safari / 525.19-Netscape

Javascript can help you with browser detection and figuring out UserAgent. Javascript可以帮助您进行浏览器检测并找出UserAgent。 Use ExternalInterface to make the Javascript talk to your flex application. 使用ExternalInterface使Javascript与Flex应用程序通信。 Here's an ExternalInterface tutorial . 这是一个ExternalInterface 教程

Your javascript: 你的javascript:

function determineBrowser()
{
    // do whatever browser checks you prefer here, then return
    // a value (a string would probably work best) that will indicate
    // to your flash what browser it is

    // I'm just gonna copy and paste an extremely
    // simple one for example purposes

    if(navigator.appName == "Netscape")
    {
        return "Netscape";
    }
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        return "Internet Explorer";
    }

    return "Not IE or Netscape";
}

Your Actionscript: 你的动作脚本:

import flash.external.ExternalInterface;

var browser: String = ExternalInterface.call("determineBrowser");

Using what I did, whatever your javascript function returns is what the browser variable in actionscript will be, so you can get any browser data you need as long as you make the javascript determine it. 使用我所做的,无论你的javascript函数返回什么是actionscript中的浏览器变量,所以你可以获得所需的任何浏览器数据,只要你让javascript确定它。

I recommend making it a little more robust than I did, but I just wanted to give you the basic idea in short enough terms to be easy to digest! 我建议让它比我更健壮,但我只是想用足够短的术语给你基本的想法,以便于消化!

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

相关问题 如何使用Flex / AS3获取浏览器时区? - How do I get browser timezone using Flex/AS3? Flex 3:如何在ItemRenderer中获取DataGridColumn的dataField? - Flex 3: How do I get the DataGridColumn's dataField in its ItemRenderer? 在浏览器中查看时,如何让我的 Flex 应用程序垂直滚动? - How do I get my Flex app to scroll vertically when view in a browser? 如何在没有浏览器工具栏的情况下从Flex创建弹出窗口? - How do I create a popup from Flex without a browser toolbar? Flex的FileReference.save()只能在用户事件处理程序中调用 - 我该如何解决这个问题? - Flex's FileReference.save() can only be called in a user event handler — how can I get around this? Flex 3:如何获取网址 - Flex 3: How do I get URL 如何根据索引对象内的值获取特定的数组索引? 柔性 - how do i get the specific array index based on value inside the index's object? flex 如何使flex只使用鼠标滚动和键盘事件有用,否则将其传递给浏览器? - How do I make flex only consume mouse scroll and keyboard events when it's useful, and otherwise pass it on to the browser? 为了创建可在线运行并在手机浏览器上运行的Flex SWF,我需要了解/做什么? - What do I need to know/do inorder to create a Flex swf that works both online, and on a phone's browser? 如何在flex中找出用户的IP地址? - How can I find out the user's IP address in flex?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM