Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
You are here: Reference > JavaScript > client-side > HTML DOM > properties > code (applet, object)

code property (applet, object)

Browser support:
Sets or retrieves the name of the Java class file that contains the Java applet.
The applet tag is not a standard HTML element, use the object tag instead wherever you can.
You can define the location of the file with the codeBase property or with the codebase parameter for the applet and the object tags, too.
The location 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. See Example 1 and 2 for details.
The code property returns the absolute URL of the Java class file if the object tag is used with the codebase parameter. See Example 3 and 4.

Syntax:

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

Possible values:

String that sets or retrieves the name of the class file.
Default: this property has no default value.

Example HTML code 1:

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

Example HTML code 2:

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

Example HTML code 3:

This example illustrates the use of the code property:
Code
HelloWorld.java
<head>
    <script type="text/javascript">
        function GetCode () {
            var applet = document.getElementById ("myApplet");
            alert (applet.code);
        }
    </script>
</head>
<body>
    <applet id="myApplet" code="HelloWorld.class" codebase="/external/examples/common/java/" style="width:200px; height:50px;">
    </applet>

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

Example HTML code 4:

Recommendation:
Code
HelloWorld.java
<head>
    <script type="text/javascript">
        function GetCode () {
            var object = document.getElementById ("myObject");
            alert (object.code);
        }
    </script>
</head>
<body>
    <object id="myObject" type="application/x-java-applet" code="HelloWorld.class" style="width:200px; height:50px;">
        <param name="codebase" value="/external/examples/common/java/" />
    </object>

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

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content