📄 applet.js
字号:
/*
* By Igor Zhukovsky. www.izhuk.com, April 2006.
*
* Use this class to output applet tags on a web page
* This resolves the IE security issue.
* (read about the issue http://izhuk.com/docs/ie7fix.html)
*
* How to use:
*
* 1. Include this script in your HTML page:
*
* <script language="javascript" src="applet.js"></script>
*
* 2. Write JavaScript code:
*
* var myapplet = new Applet(); // create new Applet object
*
* // assign necessary attributes
* myapplet.attr['code'] = 'MyClass.class';
* myapplet.attr['width'] = 200;
* myapplet.attr['height'] = 100;
* ....
*
* // assign parameters (if any)
* myapplet.param['param1'] = 'value1';
* ....
*
* myapplet.write(); // output the applet definition
*/
function Applet() {
this.param = new Object();
this.attr = new Object();
// required attributes
this.attr.width = false;
this.attr.height = false;
this.attr.code = false;
// optional attributes
this.attr.codebase = './';
this.attr.archive = false;
this.attr.id = false;
this.attr.name = false;
this.noJava = '';
this.use_classical_applet =
!((navigator.appVersion.indexOf("MSIE") >= 0) &&
(navigator.userAgent.indexOf(' MSIE 5.')==-1));
// for MSIE 5.x to run Ms Java 1.1
// = navigator.userAgent.indexOf(' MSIE 5.') > 0;
// navigator.appVersion.indexOf("Win") != -1 &&
// navigator.appVersion.indexOf("MSIE")!= -1 &&
// navigator.javaEnabled()) { // Windows, IE, java enabled
}
Applet.prototype.write = function() {
// check presence of mandatory attributes
var missing_attrs = '';
if (this.attr.code==false) {
missing_attrs += ' Applet.code';
}
if (this.attr.width==false) {
missing_attrs += ' Applet.width';
}
if (this.attr.height==false) {
missing_attrs += ' Applet.height';
}
if (missing_attrs.length > 0) {
window.alert('Missing attribute(s) :'+missing_attrs);
return;
}
if (this.use_classical_applet) {
this.writeApplet(); // using Java 1.1
return;
}
// else using JRE 1.4 or later
s = '<OBJECT classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"\n';
if (this.attr.id != false) {
s += 'id = "'+this.attr.id+'"\n';
}
s += 'codebase = "http://java.sun.com/update/1.4.2/jinstall-1_4-windows-i586.cab#Version=1,4,0,0"\n';
s += 'WIDTH = "'+this.attr.width+'" HEIGHT = "'+this.attr.height+'" >\n';
s += '<PARAM NAME = CODE VALUE = "'+this.attr.code+'" >\n';
s += '<PARAM NAME = CODEBASE VALUE = "'+this.attr.codebase+'">\n';
if (this.attr.archive != false)
s += '<PARAM NAME = "ARCHIVE" VALUE="'+this.attr.archive+'">\n';
s += '<PARAM NAME = "type" VALUE = "application/x-java-applet;version=1.4">\n';
s += '<PARAM NAME = "scriptable" VALUE = "false">\n';
for (name in this.param) {
var value = this.param[name];
s += '<PARAM NAME="'+name+'" VALUE="'+value+'">';
}
s += '<COMMENT><EMBED type = "application/x-java-applet;version=1.4"\n';
if (this.attr.id != false) {
s += 'name = "'+this.attr.id+'"\n';
}
s += 'CODE = "'+this.attr.code+'"\n';
s += 'JAVA_CODEBASE = "'+this.attr.codebase+'"\n';
if (this.attr.archive != false)
s += 'ARCHIVE = "'+this.attr.archive+'"\n';
s += 'WIDTH="'+this.attr.width+'" HEIGHT="'+this.attr.height+'"\n';
s += 'scriptable = false\n';
s += 'pluginspage = "http://java.sun.com/products/plugin/index.html#download"\n';
for (name in this.param) {
var value = this.param[name];
s += name+'="'+value+'"\n';
}
s += '><NOEMBED></NOEMBED></EMBED></COMMENT>';
s += '</OBJECT>';
//window.alert(s);
document.write(s);
} // end of Applet.write()
// creates the classical <applet> tag
Applet.prototype.writeApplet = function() {
if (this.attr.id != false && this.attr.name==false) {
this.attr.name = this.attr.id;
}
document.write('<applet ');
// write attributes of the <applet> tag
for (name in this.attr) {
var value = this.attr[name];
document.write(name+'="'+value+'" ');
}
document.write('>');
// write the applet parameters
for (name in this.param) {
var value = this.param[name];
document.write('<param name="'+name+'" value="'+value+'">');
}
document.write(this.noJava);
document.write('</applet>');
}
Applet.prototype.getAppletRef = function() {
return document.applets[this.attr.id];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -