Hi,
Does anyone know of a script so that a java applet loads last on a web page, or after the page is loaded?
Than you
Rick
Hi,
Does anyone know of a script so that a java applet loads last on a web page, or after the page is loaded?
Than you
Rick
Will this work?:
Code:<html> <head> <script type="text/javascript"> var applet = 'Applet code here..'; var doApplet = function(div){ document.getElementById(div).innerHTML = applet; }; </script> </head> <body onload="doApplet('app');"> <div id="app"></div> </body> </html>
Rick777 (01-25-2009)
Thanks , but it still did not load the page before the applet loaded up.
Thank you
Rick
Hmm, give this a try:
The first one should work though. =/Code:<html> <head> <script type="text/javascript"> var applet = 'Applet code here..'; var doApplet = function(div){ (window.onload) ? document.getElementById(div).innerHTML = applet : function() { doApplet(div) }; }; </script> </head> <body onload="doApplet('app');"> <div id="app"></div> </body> </html>
Hi I apprecite the help, but both do not let google java script load and show on the page. It still ends up waiting for the applet to load before rendering a page. I know we could create a .js file, but that would not help us on some other pages. It is just for a chat. I guess we have to wait for people to get better comps now.
Thanks
Rick
Here is the page if you are interested where I was trying.
chatpit.com/teenchat/
Last edited by jscheuer1; 01-15-2011 at 04:20 AM. Reason: remove hotlink
You don't have my code anywhere on the page....
Last edited by jscheuer1; 01-22-2009 at 04:43 PM. Reason: sense
Rick777 (01-25-2009)
Nile's idea should work, but there may be an issue with onload conflicts with other code, or other code also firing onload and if Nile's code were to fire onload, but before other onload code, it would be the same as delaying the onload event for the other code. Often a 0 or low value timeout will be all that's required to delay execution until after other onload code has run. If you do script your Java Applet, it will be unavailable for non-javascript users unless there is a non-javascript fall back for it, like within a <noscript></noscript> tag.
To deal with the first issue, one should use addEventListener/attachEvent to set the onload event, for the second, a simple time out could be fine (increasing the timeout may be required, though order of execution may still get held up. If so, another strategy may be required for the delay part of this scheme, like determining where on the page to add the script, even splitting execution of the two listeners, as they can behave differently in regard to timing, basic example:
Code:<html> <head> <script type="text/javascript"> var doApplet = function(){ var applet = 'Applet code here..'; setTimeout(function(){document.getElementById('app').innerHTML = applet;}, 0); }; if (window.addEventListener) window.addEventListener('load', doApplet, false); else if (window.attachEvent) window.attachEvent('onload', doApplet); </script> </head> <body> <div id="app"></div> </body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Hi,
Oh I took it off after I tested both scripts. The fist one showed the most promise, but I it slighty altered the page a bit so I took it off. Would the best solution be to get the applet in a iframe? I do not know how to even do that though. I may just end up putting on a pop up for the java applet so a user can start it when they wish.
Thank you for all your help.
Rick
Hi,
I just tried this one too:
http://www.chatpit.com/1test/
Not a lot off difference, and it also moves an ad to, where I do not wish it to be.
Thank you
Rick
A good effort. But you have a bit to learn about how to make a valid string variable in javascript, particularly as regards both multi-line string variable values and proper quoting conventions.
Also, if the applet code is already on the page, as it is in your current effort, writing it to the page later, even if in the same location is more or less no different than having no script for this purpose.
With me so far?
Anyways, I was thinking more like this for the script (ask questions if you don't understand the changes from what you had):
And then in the body of the page, where the existing applet code is:Code:<script type="text/javascript"> var doApplet = function(){ var applet = '<APPLET NAME="DigiChat" CODEBASE="http://67.19.116.210/DigiChat/DigiClasses/"' + 'CODE="com.diginet.digichat.client.DigiChatApplet"' + 'HEIGHT=85 WIDTH=210 ALIGN="MIDDLE"' + 'ARCHIVE=Client_5_1_0_7.jar MAYSCRIPT>' + '<PARAM NAME=cabbase value=Client_5_1_0_7.cab>' + '<PARAM NAME=siteID VALUE=253220019>' + '<param name="room" value="ThE ChAtPiT">' + '<PARAM NAME=MenuItem1 VALUE=Zubee! Online>' + '<PARAM NAME=MenuLocation1 VALUE=http://www.zubee.com>' + '<PARAM NAME=KickUserHTML VALUE="http://www.chatpit.com/chatrooms.html">' + '<PARAM NAME=helpURL VALUE="http://www.zubee.com/">' + '<param name="background" value="000000">' + '<param name="textcolor" value="00FF00">DigiChat free teen chat rooms require a Java Compatible web browser to view our free teen chat rooms. http://java.sun.com/j2se/1.4.2/download.html</applet>'; setTimeout(function(){document.getElementById('app').innerHTML = applet;}, 0); }; if (window.addEventListener) window.addEventListener('load', doApplet, false); else if (window.attachEvent) window.attachEvent('onload', doApplet); </script>
The only change there being that the applet itself is now enclosed in <noscript></noscript> tags. This allows non-javascript users to see and use it, and at the same time takes it out of the flow of the document for javascript enabled users, so that for them it will only appear after page load when the script inserts its code to the page.Code:<!-- *** START APPLET CODE *** --><center><div id="app"><noscript> <APPLET NAME='DigiChat' CODEBASE='http://67.19.116.210/DigiChat/DigiClasses/' CODE='com.diginet.digichat.client.DigiChatApplet' HEIGHT=85 WIDTH=210 ALIGN='MIDDLE' ARCHIVE=Client_5_1_0_7.jar MAYSCRIPT> <PARAM NAME=cabbase value=Client_5_1_0_7.cab> <PARAM NAME=siteID VALUE=253220019> <param name="room" value="ThE ChAtPiT"> <PARAM NAME=MenuItem1 VALUE=Zubee! Online> <PARAM NAME=MenuLocation1 VALUE=http://www.zubee.com> <PARAM NAME=KickUserHTML VALUE='http://www.chatpit.com/chatrooms.html'> <PARAM NAME=helpURL VALUE='http://www.zubee.com/'> <param name="background" value="000000"> <param name="textcolor" value="00FF00">DigiChat free teen chat rooms require a Java Compatible web browser to view our free teen chat rooms. http://java.sun.com/j2se/1.4.2/download.html</applet></noscript></div>
Now, we may have a done deal at this point, but there is still the matter of whether or not our timeout delays the applet's initialization in the manner that you desire. If not, let me know because I have a good idea where to go from here to work that last part out.
Then again, as I say, this may be just the ticket, if so let's leave well enough alone.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Rick777 (01-25-2009)
Bookmarks