HTML
Code:
<html>
<head>
<style>
.one{
background-color:#FF0000;
width:400px;
height:400px;
float:left;
}
.two{
background-color:#00FF00;
width:400px;
height:400px;
float:left;
}
.three{
background-color:#0000FF;
width:400px;
height:400px;
float:left;
}
</style>
<script type="text/javascript" src="AppletObject.js"></script>
</head>
<body>
<div class="one"></div>
<div class="two" id="appletDiv"></div>
<div class="three"></div>
<a href='javascript:var ao = new AppletObject("snakeAI5","http://www.robotacid.com/PBeta/snakeAI5/snakeAI5.jar","400","400","true");ao.write("appletDiv");'>Add Applet</a>
</body>
</html>
JavaScript file AppletObject.js
Code:
// Java Applet Object
function AppletObject(code, archive, width, height, mayscript){
this.code = code;
this.archive = archive;
this.library = "";
this.width = width;
this.height = height;
this.mayscript = mayscript;
this.write = function(div){
var d=document.getElementById(div);
var string = '<applet code="'+this.code+'" archive="'+this.archive+this.library+'" width="'+this.width+'" height="'+this.height+'" mayscript="'+this.mayscript+'">';
for(var i = 0; i < this.param.length; i++){
string += '<param name="'+this.param[i].name+' value="'+this.param[i].value+'>';
}
string += this.alt;
string += '</applet>';
d.innerHTML = string;
};
this.addParam = function(name, value){
var appletParam = new Object();
appletParam.name = name;
appletParam.value = value;
this.param.push(appletParam);
};
this.addLibrary = function(file){
if(file.charAt(0) == ',' || this.library.charAt(this.library.length-1) == ','){
library += file;
} else {
library += ',' + file;
}
}
this.folder = this.archive.substring(0, this.archive.lastIndexOf("/")) + "/";
this.alt = 'To view this content, you need to install Java from <A HREF="http://java.com">java.com</A>';
this.param = new Array();
}
Voila. One AppletObject.js. (functions: addParam(name, value), addLibrary(file), write(div))
I've found you can pretty much concat a whole world of js commands into a href, so adding params and libraries could be managed by some behind the scenes functions.
For jogl applets you just need to change the code value and set a few params.
I need to build a html ripper for Flash now that is going to get the properties of applets it finds on pages on my site. I've got a basic one running inside the Flash, but I'd rather format everything in PHP to give to Flash, rather than let Flash make a hash of it with it's crappy string management.
Anyone wishing to pelt me with their 2 cents is welcome.