You are here: Reference > JavaScript > client-side > HTML DOM > properties > codeBase (applet, object)

codeBase property (applet, object)

Browser support:
Sets or retrieves the base location that relative URLs specified in the classid, data and archive properties are relative to.
The codeBase property always returns the absolute URL of the base location in Firefox, Opera, Google Chrome and Safari.

Syntax:

object.codeBase;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: codeBase

Possible values:

String that sets or retrieves the base URL to use.
The URL can be an absolute or relative path as well. Relative paths are relative to the base URL. The base URL is the location of the current document, but it can be overridden by the base tag.
The URL may contain version information at the end of the value for object elements. In that case, if the component required by the object element does not exist on the client computer or it is older than the version specified by the codeBase property, browsers try to download the required one.
The form of the version information is URL#version='high-major-number','low-major-number','high-minor-number', 'low-minor-number'. See Example 2 for details.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the code and the codebase attributes for object tags:
Code
HelloWorld.java
<object type="application/x-java-applet" code="HelloWorld.class" 
        codebase="/external/examples/common/java/" width="200px" height="50px">
</object>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the codeBase attribute with Macromedia Flash Player.
It clearly focuses on cross-browser support only, and it isn’t standards-compliant, but there isn't any standards-compliant cross-browser way to embed a Flash application into a document with Flash Player detection.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="120" 
        codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0">
    <param name="movie" value="flash.swf" />
    <!-- Optional params -->
    <param name="play" value="true" />
    <param name="loop" value="true" />
    <param name="quality" value="high" />
    <!-- END Optional -->
    <embed src="flash.swf" width="300" height="120" play="true" 
        loop="true" quality="high" 
        pluginspage="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" /> 
</object>
Did you find this example helpful? yes no

Example HTML code 3:

This example illustrates the use of the codebase property for object tags:
Code
HelloWorld.java
<head>
    <script type="text/javascript">
        function GetCodeBase () {
            var object = document.getElementById ("myObject");
            alert (object.codeBase);
        }
    </script>
</head>
<body>
    <object id="myObject" type="application/x-java-applet" code="HelloWorld.class" 
            codebase="/external/examples/common/java/" width="200px" height="50px">
    </object>

    <button onclick="GetCodeBase ();">Get codebase!</button>
</body>
Did you find this example helpful? yes no

Example HTML code 4:

This example has similar functionality to the previous one, but it creates the Macromedia Flash Movie dynamically. The codeBase property is specified in the flash.js file.
Code
flash.js
<head>
    <script type="text/javascript" src="flash.js"></script>
    <script type="text/javascript">
        function CreateFlash () {
            var flashContainer = document.getElementById ("flashContainer");
            var flash = new Flash ();
            flash.Init (flashContainer, "flash.swf", 300, 200);
            flash.SetParam ('bgcolor', '#000000');
            flash.SetParam ('quality', 'high');
            flash.Create ();
        }
    </script>
</head>
<body onload="CreateFlash ()">
    <div id="flashContainer"></div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content