Jaffer
Jaffer

Reputation: 755

Detect Type and Version of Browser from within Flash

I want to know the type and version the browser that the user is running from within my Flex 4 application. I know I can get that information by using ExternalInterface to call Javascript. I know I can get that information from the server.

I'm looking for a way to get that information directly from actionscript. I mean, isn't there a global variable or something that keeps this information?

Upvotes: 7

Views: 5046

Answers (1)

goliatone
goliatone

Reputation: 2174

You can't since you don't have any global variables as you mention.

But whty not use ExternalInterface and JavaScript?.

var method:XML = <![CDATA[
     function( ){ 
         return { appName: navigator.appName, version:navigator.appVersion};}
    ]]>

var o:Object = ExternalInterface.call( method );
trace( "app name ",o.appName,"version ", o.version )

If you put it in a class as a static method, for you it would be as transparent as calling an intrinsic class...

package {
    import flash.external.ExternalInterface;


    public class BrowserUtils {

        private static const CHECK_VERSION:XML = <![CDATA[
             function( ) { 
                return { appName: navigator.appName, version:navigator.appVersion };
                }
            ]]>;

        public static function getVersion( ):Object {
            if ( !ExternalInterface.available ) return null;            

            return ExternalInterface.call( CHECK_VERSION );
        }

    }

}

Upvotes: 9

Related Questions