Hi there.
I'd like to know what Browser the User is using to view my Flex application. How can I get at the User Agent string and other information?
Hi there.
I'd like to know what Browser the User is using to view my Flex application. How can I get at the User Agent string and other information?
Javascript can help you with browser detection and figuring out UserAgent. Use ExternalInterface to make the Javascript talk to your flex application. Here's an ExternalInterface tutorial.
Your 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.
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!
Hello,
you can 'embed' your javascript inside AS3 code like this :
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):
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