HTML applet Tag
The <applet> tag in HTML was used to embed Java applets into any HTML document. The <applet> tag was deprecated in HTML 4.01, and it’s support has been completely discontinued starting from HTML 5. Alternatives available in HTML 5 are the <embed> and the <object> tags. There are still some browsers that support the <applet> tag with the help of some additional plug-ins/installations to work. Internet Explorer 11 and earlier versions with the help of plug-ins.
Applet Tag is not supported in HTML5. The <applet> tag takes a number of attributes, with one of the most important being the code attribute. This code attribute is used to link a Java applet to the concerned HTML document. It specifies the file name of the Java applet.
Attributes: This tag accepts the following attributes:
- align: Specifies the alignment of an applet.
- alt: Specifies an alternate text for an applet.
- archive: Specifies the location of an archive file.
- border: Specifies the border around the applet panel.
- codebase: Specifies a relative base URL for applets specified in the code attribute.
- height: Specifies the height of an applet.
- hspace: Defines the horizontal spacing around an applet.
- mayscript: Indicates whether the Java applet is allowed to access the scripting objects of the web page.
- name: Defines the name for an applet (to use in scripts)
- vspace: Defines the vertical spacing around an applet.
- width: Specifies the width of an applet.
Syntax:
<applet attribute1 attribute2....> <param parameter1> <param parameter2> .... </applet>
The following Examples explain the applet tag:
Example 1: Here, HelloWorld is the class file, which contains the applet. The width and height attributes determine the width and height of the applet in pixels when it is opened in the browser.
Attributes available to be used in conjunction with the <applet> tag are as follows:
HTML
<!DOCTYPE html> < html > <!-- applet code starts here --> < applet code = "HelloWorld" > <!-- applet code ends here --> </ applet > </ html > |
Parameters: Parameters are quite similar to command-line arguments in the sense that they provide a way to pass information to the applet after it has started. All the information available to the applet before it starts is said to be hard-coded i.e. embedded within it. Parameters make it possible to generate and use data during run-time of the applet.
Syntax:
<param name=parameter_name value=parameter_value>
The name assigned to the name attribute of the param tag is used by the applet code as a variable to access the parameter value specified in the value attribute. In this way, the applet is able to interact with the HTML page where it is embedded, and can work on values provided to it by the page during run-time.
Example 2: In this piece of code, the applet file HelloWorld can use the variable named message to access the value stored in it, which is “HelloWorld”.
HTML
<!DOCTYPE html> < html > <!-- applet code starts here --> < applet code = "HelloWorld" > < param name = "message" value = "HelloWorld" > <!-- applet code ends here --> </ applet > </ html > |
Supported Browsers:
- Firefox
- Safari
Please Login to comment...