Copy link to clipboard
Copied
how to detect browser & version in as3?
Copy link to clipboard
Copied
Hi Venkon,
You can use ExternalInterface.call("window.navigator.userAgent") with this u can detect the browser details.
Copy link to clipboard
Copied
that is detected total like : Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;
but i want only like MSIE 8.0
or
Firefox 11.0
Copy link to clipboard
Copied
Use this code
package
{
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.motion.easing.Elastic;
public class Main extends Sprite
{
private var userAgent:String;
public function Main():void
{
more.addEventListener(MouseEvent.MOUSE_UP, showFull);
browserTxt.text = getUserAgent();
}
private function getUserAgent():String
{
try
{
userAgent = ExternalInterface.call("window.navigator.userAgent.toString");
var browser:String = "[Unknown Browser]";
if (userAgent.indexOf("Safari") != -1)
{
browser = "Safari";
}
if (userAgent.indexOf("Firefox") != -1)
{
browser = "Firefox";
}
if (userAgent.indexOf("Chrome") != -1)
{
browser = "Chrome";
}
if (userAgent.indexOf("MSIE") != -1)
{
browser = "Internet Explorer";
}
if (userAgent.indexOf("Opera") != -1)
{
browser = "Opera";
}
}
catch (e:Error)
{
//could not access ExternalInterface in containing page
return "[No ExternalInterface]";
}
return browser;
}
private function showFull(e:MouseEvent):void
{
info.fullInfo.text = userAgent;
var tween:Tween = new Tween(info,"y",Elastic.easeOut,info.y-10,180,0.5,true);
}
}
}
place a textfield on stage with instance browserTxt and a button with instance more and movieclip with instance info inside movieclip place a textfield with instance fullInfo. Test it
Copy link to clipboard
Copied
already tested this one. but this is showing full address like
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727;
but i want only like MSIE 8.0