4 Replies Latest reply: Apr 27, 2012 12:47 AM by Venkom RSS

    how to detect browser & version?

    Venkom Community Member

      how to detect browser & version in as3?

        • 1. Re: how to detect browser & version?
          kiran1989 Community Member

          Hi Venkon,

           

           

          You can use ExternalInterface.call("window.navigator.userAgent") with this u can detect the browser details.

          • 2. Re: how to detect browser & version?
            Venkom Community Member

            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

            • 3. Re: how to detect browser & version?
              kiran1989 Community Member

              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

              • 4. Re: how to detect browser & version?
                Venkom Community Member

                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