Handling multiple browser types

In most cases, you must write your HTML page's scripts to handle multiple browser types. Getting a reference to the Flash application object is not the same in Internet Explorer as it is in Netscape-based browsers such as FireFox.

To write script that is browser independent, you examine the name of the navigator object and return a reference to the Macromedia Flash application based on that. The following code gets a reference to the Flash application in all major browsers:

<html><head>
<title>wrapper/BrowserAwareAddCallbackWrapper.html</title>
</head>
<body scroll='no'>

<SCRIPT LANGUAGE="JavaScript">
    // Internet Explorer and Mozilla-based browsers refer to the Flash application 
    // object differently.
    // This function returns the appropriate reference, depending on the browser.
    function getMyApp(appName) {
        if (navigator.appName.indexOf ("Microsoft") !=-1) {
            return window[appName];
        } else {
            return document[appName];
        }
    }

    function callApp() {
        window.document.title = document.getElementById("newTitle").value;
        getMyApp("mySwf").myFlexFunction(window.document.title);
    }
</SCRIPT>

<h1>AddCallBack Wrapper</h1>

<form id="f1">
    Enter a new title: <input type="text" size="30" id="newTitle" onchange="callApp()"> 
</form>

<table width='100%' height='100%' cellspacing='0' cellpadding='0'>
    <tr>
        <td valign='top'>
            <object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' height='200' width='400'>
                <param name='src' value='AddCallbackExample.swf'/>
                <param name='flashVars' value=''/>
                <embed name='mySwf' src='AddCallbackExample.swf' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' height='100%' width='100%' flashVars=''/>
            </object>
        </td>
    </tr>
</table>

</body></html>

Flex 2.01

Take a survey


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flex/201/html/passingarguments_086_16.html