Deploying Java Applets in a Mixed Browser Environment

by Clain Brand.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on java  

You are here: Categories » Computers and technology » JAVA

You can deploy applets for users of both Internet Explorer and the Mozilla family of browsers in one of two ways:

Through pure HTML
Through JavaScript

Using Pure HTML

When using a pure HTML approach to deploy applets in a mixed-browser environment, note the following:

1. Internet Explorer

Recognizes the object tag
Ignores the contents of the comment tag

2. Mozilla browsers

Ignore an object tag with the classid attribute
Interpret the contents of the comment tag

Consider the following example code from an HTML page:

<object classid="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA"
<param name="code" value="Applet1.class">
<comment>
<embed code="Applet1.class"
type="application/x-java-applet;jpi-version=1.6">
<noembed>
No Java Support.
</noembed>
</embed>
</comment>
</object>

Using JavaScript

Instead of using the pure HTML approach described above, you can use JavaScript to deploy applets in a mixed-browser environment. Through JavaScript, you:

1. Detect the user's browser through the appName variable.
2. Use the document.write() method to write a tag based on the value of the appName variable:

If the browser name equals "Netscape", write the embed tag.
If the browser name equals "Microsoft Internet Explorer", write the object tag.

In the following example, the document.write() method outputs either an embed or object tag for each user "on the fly":

<html>
<script language="Javascript">
var _app = navigator.appName;
if (_app == 'Netscape') {
document.write('<embed code="Applet1.class"',
'width="200"',
'height="200"',
'type="application/x-java-applet;version=1.6">');
}
else if (_app == 'Microsoft Internet Explorer') {
document.write('<OBJECT ',
'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"',
'width="200"',
'height="200">',
'<PARAM name="code" value="Applet1.class">',
'</OBJECT>');
}
else {
document.write('<p>Sorry, unsupported browser.</p>');
}
</script>
</html>

Leave a comment or ask a question
Total comments: 0

JAVA Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
Operator Precedence in programming languages - Operator precedence deciphers the order in which calculations in an expression occur. Looking at the calculation example 3 + 4 * 6, the answer could be calculated by adding 3 and 4, which gives (more...)
Arithmetic Assignment Operators - The following assignment operators are similar to the increment and decrement operators that we have just seen. They are used so that you do not need to enter the source variable twice when ass (more...)
Bitwise Operators - The following table shows the standard bitwise operators in Java and a description of them. (more...)
Invocation Chaining - Invocation chaining means that you are not limited to merely accessing one class/object member in a given statement with the . operator but may continue to access further members in a given stateme (more...)
Regular Expressions in Java - A regular expression is a code that is used to match a pattern in a given string and is new to Java 1.4. Regular expressions are made up of normal characters and metacharacters. Normal characters a (more...)
Character Escape Sequences - Character escape sequences allow for a character to be interpreted differently than its literal value. Character escape sequences are defined using the backslash (\) character, followed by th (more...)
Conditional Statements - The ability to choose the path that your program takes, based on any given data, is the key to all functionality in programming. In order to create conditional statements, we must first learn a (more...)
Java Methods - Methods are used as the building blocks of your program, performing tasks that can be called again and again and using the same code to perform the task each time. The basic but fundamental parts o (more...)
Variable Scope - The scope of a variable is the area in which a variable belongs, specified by the area in which it is declared. The following example code contains two declared variables, one inside a code block a (more...)
What is a Java Package - A Java package is a collection of related classes that can be imported into your program to support your software. They also provide namespace management, as well as access protection. (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.