This is a generic AppletLoader (javascript) Works with all Applet and SUN+MS JVM
No Java splash, no computer freez (not a long one ;-)) , and finally no click to activate control.
http://demo.dzzd.net/JScripts/
http://demo.dzzd.net/JScripts/index2.htm
please let comments and bugs on your platforms as the following:
FF 1.5 Windows XP (SUN1.6) => Ok
FF 2.0 Windows XP (SUN1.6) => Ok
IE 1.6 Windows XP (MS1.1+SUN1.6) => Ok
Need to polish source code a little before releasing
UPDATE:
a different layout with same applets using a single target window http://demo.dzzd.net/JScripts/index2.htm
UPDATE:
A first source code, it may be improved but this is the one currently used. you can view html source code of the above url to see how to use it
UPDATE:
Source code updated (I introduced a MSJVM bugs while trying to resolve a bug appening in safari browser), it is now resolved new version works with MSJVM
UPDATE:
Source code updated, add message when unable to start applet also ask the user to install java if unable to detect any JVM
UPDATE:
Source code updated, now works on Safari 3.0.4 windows XP
UPDATE:
Better Jar and classe file cache enable fast switch between applet once an applet have been loaded it can be started immediatly
UPDATE:
Java script refound from scratch
/**
* 3DzzDAppletScript.js
*
* This source code is a part of 3DzzD Web 3D engine you may use it as long as you provide the orignal source author and website and this comment unmodified
*
* @author bruno augier
* @email bruno.augier@dzzd.net
* @website http://dzzd.net/
* @version 1.00 2007/12/03
*/
var jvmInited=false;
var imageLoad=new Image();
imageLoad.src="INIT.GIF";
var preloadingJar = new Array();
function loadApplet(targetAppletId,appletName,appletTag,width,height,preloadJarFiles)
{
if(document.getElementById(appletName))
return;
var msg="Loading Applet "+ appletName;
window.status=msg;
var target=document.getElementById(targetAppletId);
var html="";
html+="<TABLE ID=\""+targetAppletId+"LOADER\" cellSpacing=0 cellPadding=0 WIDTH=\""+width+"\" HEIGHT=\""+height+"\" STYLE=\"border:0\" >";
html+="<TR><TD vAlign=\"center\" align=\"middle\">";
html+="<IMG ";
html+=" ALT=\""+ msg + "\" ";
html+=" SRC=\"INIT.GIF\" ";
html+=" >";
html+="</TD></TR></TABLE><DIV STYLE=\"visibility:hidden\" ID=\""+targetAppletId+"APPLET\"></DIV>";
target.innerHTML=html;
var nbApplet=document.applets.length;
if(preloadJarFiles!=null && preloadJarFiles.replace(" ","")!="")
{
preloadJars(preloadJarFiles);
setTimeout("showAppletOnceStartedPreload(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\",\""+preloadJarFiles+"\","+nbApplet+")",100);
}
else
{
setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",100);
}
}
function showAppletOnceStartedPreload(targetAppletId,appletName,appletTag,width,height,preloadJarFiles,nbApplet)
{
if(!isJarsPreloaded(preloadJarFiles))
setTimeout("showAppletOnceStartedPreload(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\",\""+preloadJarFiles+"\","+nbApplet+")",1250);
else
setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
}
function showAppletOnceStarted(targetAppletId,appletName,appletTag,width,height,nbApplet)
{
var target=document.getElementById(targetAppletId+"APPLET");
if(target.innerHTML.toUpperCase().indexOf("<APPLET ")==-1)
{
target.innerHTML+=appletTag;
setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
return;
}
if(jvmInited)
{
if(document.applets.length>nbApplet)
{
var applet=document.getElementById(appletName);
if(applet!=null)
{
if(document.applets[appletName])
{
var msg="Applet loaded and started " + appletName;
window.status=msg;
setTimeout("showApplet(\""+targetAppletId+"\",\""+appletName+"\",\""+width+"\",\""+height+"\")",250);
return;
}
}
}
}
setTimeout("showAppletOnceStarted(\""+targetAppletId+"\",\""+appletName+"\",\""+appletTag+"\",\""+width+"\",\""+height+"\","+nbApplet+")",250);
}
function showApplet(targetAppletId,appletName,width,height)
{
var applet=document.getElementById(appletName);
var loader=document.getElementById(targetAppletId+"LOADER");
loader.style.display="none";
applet.width=width;
applet.height=height;
applet.style.width=width;
applet.style.height=height;
var target=document.getElementById(targetAppletId+"APPLET");
target.style.visibility="visible";
}
function preloadJars(files)
{
var fileArray=files.replace(";",",").split(",");
for(var c=0;c<fileArray.length;c++)
{
preloadJar(fileArray[c]);
}
}
function isJarsPreloaded(files)
{
var fileArray=files.replace(";",",").split(",");
for(var c=0;c<fileArray.length;c++)
{
if(!fileArray[c])
return false;
}
return true;
}
function isJarPreloaded(name)
{
if(preloadingJar[name]==null)
return false;
return preloadingJar[name];
}
function preloadJar(name)
{
if(preloadingJar[name])
return;
preloadingJar[name]=false;
var f=window.frames[name];
if(!f)
{
document.body.innerHTML+="<IFRAME NAME=\""+name+"\" WIDTH=0 HEIGHT=0 STYLE=\"border:0\"></IFRAME>";
f=window.frames[name];
f.document.open("text/html");
var iframeHTML="";
iframeHTML+="<HTML><BODY onload=\"parent.preloadingJar['"+name+"']=true;\" SCROLL=NO STYLE=\"margin:0\" >";
iframeHTML+="<APPLET ARCHIVE=\""+name+"\" NAME=\""+name+"\" WIDTH=0 HEIGHT=0 ";
iframeHTML+=" CODE = \"java.applet.Applet\" ";
iframeHTML+="</APPLET>";
iframeHTML+="</BODY></HTML>";
f.document.write(iframeHTML);
f.document.close();
}
}
var initJVMCount=0;
/**
* Initialise Java JVM, this may hang few seconds
*/
function loadJVM()
{
if(jvmInited)
return;
if(initJVMCount>15)
{
if(confirm("Java Plugin requiered, do you want to instal Java Plugin ?"))
window.location.href="http://java.com/";
jvmInited=true;
return;
}
var f=window.frames["JVMLOADER"];
if(!f)
{
document.body.innerHTML+="<IFRAME NAME=\"JVMLOADER\" WIDTH=0 HEIGHT=0 STYLE=\"border:0\"></IFRAME>";
f=window.frames["JVMLOADER"];
f.document.open("text/html");
var iframeHTML="";
iframeHTML+="<HTML><BODY SCROLL=NO STYLE=\"margin:0\" >";
iframeHTML+="<APPLET WIDTH=0 HEIGHT=0 ";
iframeHTML+=" CODE = \"java.applet.Applet\" ";
iframeHTML+="</APPLET>";
iframeHTML+="</BODY></HTML>";
f.document.write(iframeHTML);
f.document.close();
}
if(f.document.applets.length==0)
{
setTimeout("loadJVM()",2000);
initJVMCount++;
return;
}
// Workaround for Safari 3.0.4 embeded code crash windows XP with safari ?!
if(navigator.userAgent.toUpperCase().indexOf("SAFARI")==-1)
{
try
{
if(!f.document.applets[0].isActive())
{
setTimeout("loadJVM()",500);
initJVMCount++;
return;
}
}
catch(e)
{
setTimeout("loadJVM()",500);
initJVMCount++;
return;
}
}
jvmInited=true;
f.document.open("text/html");
var iframeHTML="";
iframeHTML+="<HTML><BODY SCROLL=NO STYLE=\"margin:0\" >";
iframeHTML+="</BODY></HTML>";
f.document.write(iframeHTML);
f.document.close();
}