View Full Version : Java Applet
Rick777
01-22-2009, 12:35 AM
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?:
<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-22-2009, 03:02 AM
Thanks , but it still did not load the page before the applet loaded up.
Thank you
Rick
Hmm, give this a try:
<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>
The first one should work though. =/
Rick777
01-22-2009, 06:47 AM
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/
You don't have my code anywhere on the page....
jscheuer1
01-22-2009, 05:57 PM
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:
<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>
Rick777
01-23-2009, 01:23 AM
You don't have my code anywhere on the page....
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
Rick777
01-23-2009, 01:40 AM
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
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:
<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>
jscheuer1
01-23-2009, 04:43 AM
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):
<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>
And then in the body of the page, where the existing applet code is:
<!-- *** 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>
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.
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.
Rick777
01-23-2009, 06:31 AM
http://www.chatpit.com/1test/
Thanks guys, I think you have it perfect. Two questions if I may, how would I add say add another 1 second, or another.5 second delay. Is there any way to keep the one google ad where it was before? I may just take that one ad off anyways.
Thank you
Rick
Rick777
01-23-2009, 06:37 AM
Oh, is there anyway to do this without haveing to put two applet codes on the page?
Just keeping one in the body tag?
Thank you
Rick
jscheuer1
01-23-2009, 06:42 AM
The delay length is set here:
setTimeout(function(){document.getElementById('app').innerHTML = applet;}, 0);
The 0 is the number of milliseconds delay. But that's a little misleading. What 0 does is delay execution until the script interpreter isn't busy with something else. If you were to make it 1000, that would add a 1 second delay on top of that. 5000 would add 5 seconds.
As far as where anything else can go on the page, it shouldn't matter. But if it does, we can probably work that out.
Rick777
01-23-2009, 08:40 AM
Okay sounds good. What do you have in mind to work out? Do you also have an option for not having the applet code in the head tag?
Thank you
Rick
Here is what I woukd like the page to look.
http://www.chatpit.com/teenchat/
The delay length is set here:
setTimeout(function(){document.getElementById('app').innerHTML = applet;}, 0);
The 0 is the number of milliseconds delay. But that's a little misleading. What 0 does is delay execution until the script interpreter isn't busy with something else. If you were to make it 1000, that would add a 1 second delay on top of that. 5000 would add 5 seconds.
As far as where anything else can go on the page, it shouldn't matter. But if it does, we can probably work that out.
Rick777
01-23-2009, 08:53 AM
http://www.chatpit.com/1test/
I managed to fix the ad part.
Rick
jscheuer1
01-23-2009, 04:08 PM
What I meant by:
As far as where anything else can go on the page, it shouldn't matter. But if it does, we can probably work that out.
I meant that if moving other things around on the page caused our current solution to stop working as desired, we could probably work that out. I also meant that I didn't think that moving other things around would be a problem.
Anyways, looks like this thread is resolved, right?
Rick777
01-23-2009, 09:33 PM
I was hoping there was another solution other than having two applet codes on the page. But this solution looks like it will work great. Who do I pay for it?
Thank you
Rick
Rick777
01-23-2009, 10:07 PM
Or to I just make a donation to any of the links posted?
Thank you
Rick
jscheuer1
01-24-2009, 01:33 AM
About having two applet codes - the way that works out is that if a user has javascript disabled, they get the second code, things will not load up as you desired, and other scripts will not run, but at least they will still be able to use the applet. With most users (those with javascript enabled), they will get the first code - in the load order that you have set for it.
This is a very common practice in javascript - providing a fall back for non-javascript enabled users via the noscript tag.
However, don't worry about the duplicate code. Regardless of whether or not a given user has javascript enabled, their browser will only have to (be able to) parse one of them.
As for any payment/donation. None is required. I'm always happy when one of my favorite charities gets some help. And if you feel motivated to compensate me directly, you may always donate to my PayPal account. If you want to do that, and need help doing so, let me know. Otherwise, just click on one of the donation links for one of my favorite charities. Or - go merrily on your way. It's all up to you, no payment or donation is required.
Rick777
01-24-2009, 02:24 AM
Sounds fair, I can you see if I have it setup correctly on this page first:
http://www.chatpit.com/teenchat/
I have already seen one issue where the applet does not load, when I used the back button, I am willing to try it with the code on for a few days to see what happens. The reason I was hoping I could just get one applet on the page is because I have a huge one on here:http://www.chatpit.com/index.htm
This solution I could not use for that page.
I was thinking 25 and 25 for the current work or I could just give you 50,
Please advise.
Thank you
Rick
jscheuer1
01-24-2009, 06:47 PM
This looks like a good solution (tested in Opera, IE, Google Chrome, Safari Win, Firefox):
You can actually make this an external script, save in a plain text editor as appdelay.js:
(function(){
if (window.opera) {
var applet = document.getElementById('app').innerHTML;
document.getElementById('app').innerHTML = '';
}
else
var applet = document.getElementById('app').removeChild(document.getElementById('theapp'));
var doApplet = function(){
if (window.opera)
setTimeout(function(){document.getElementById('app').innerHTML = applet;}, 0);
else
setTimeout(function(){document.getElementById('app').appendChild(applet);}, 0);
};
if (window.addEventListener)
window.addEventListener('load', doApplet, false);
else if (window.attachEvent)
window.attachEvent('onload', doApplet);
})();
Next, surround your applet code, and anything else associated with it whose appearance you want to be delayed with these two div elements (the id's are important), and follow that with the script call, ex:
<div id="app"><div id="theapp"><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="396B9C">
<param name="textcolor" value="FFFFFF">DigiChat free teen chat rooms require a Java Compatible web browser to view our free teen chat rooms. World Chat Teen Chat Teen Talk
Afghanistan
Albania
Algeria
Andorr . . .
. . . New Zealand
Message Boards
</applet>
<!-- *** END APPLET CODE *** -->
<font color="#FFFFFF"><font face="Comic Sans MS"><font size=-3><b>Teen chatters under the age of 18 are advised to get parental permission before entering our teen chat.</b></font></font></font>
</div>
</div><script src="appdelay.js" type="text/javascript"></script></td>
Make sure that the appdelay.js file is in the same folder as the page.
BTW, as far as I know, all of this stuff:
Afghanistan
Albania
Algeria
Andorr . . .
. . . New Zealand
Message Boards
Is just text to be displayed in the event that the browser cannot render the applet. Is all that really necessary, or does it also have some other purpose that I'm unaware of?
If you want to pay me, send me an email by going to:
http://www.dynamicdrive.com/forums/member.php?u=2033
click on Contact Info and then on:
Send a message via email to jscheuer1
use the address it shows, or just take that address to PayPal.com and send money to me using it as the recipient.
P.S. 50 dollars is fine by me.
Rick777
01-25-2009, 03:49 AM
http://www.chatpit.com/teenchat/
http://www.chatpit.com/index.htm
Thanks guys, I have added the code to both pages.
I hope I got it right.
Rick
jscheuer1
01-25-2009, 03:47 PM
I would like to clarify. We're doing all of this in the first place in order to delay the appearance of the chat applet until after the page loads, right? If I've got the concept wrong, then just what is it? Anyways, if this is the idea, if during any particular load of either of these pages the page takes longer than usual to load, this will mean that it will take longer than usual for the applet to show up, that's part and parcel of what we've done.
Also your pages are inefficiently coded and invalid (scary word, it just means that they don't precisely follow coding standards, instead relying upon error correction and quirks in browsers). I just thought you should know that, but it doesn't really impact much what we are doing with this particular thing.
The only serious problems in that regard (really the only serious problems at all) I see are that you removed one of the closing </div> tags on both pages. On http://www.chatpit.com/teenchat/ that would be here:
. . . lor_text = "CCCCCC";
google_color_url = "999999";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><script src="appdelay.js" type="text/javascript"></script></td>
On http://www.chatpit.com/index.htm it would be here:
. . . h Africa
Tanzania
Tunisia
Zimbabwe
Australia
Fiji
New Zealand
Message Boards
</applet><!-- *** END APPLET CODE *** -->
</div></div><script src="appdelay.js" type="text/javascript"></script><font color="#FFFFFF"><font face="Comic Sans MS"><font size=-3><b>Teen chatters under the age of 18 are advised to get parental permission before entering our teen chat.</b></font></font></font></td>
</tr>
</table>
Most browsers will error correct for that, but in IE it is quite possible that the browser will hang, unable to complete the loading of the page. This in fact happens on the http://www.chatpit.com/teenchat/ page. So put both of those back in.
Now, (also on that page) it's a bit risky to inclucde the Google ad scripts in the area that is removed and reinserted, but it appears to work out OK. And I would think that on the other page you might want to include:
<font color="#FFFFFF"><font face="Comic Sans MS"><font size=-3><b>Teen chatters under the age of 18 are advised to get parental permission before entering our teen chat.</b></font></font></font>
in the section that is being delayed, but that's just a judgement call.
Either way, you may want to set the height of that table:
<table border width="210" height="125" bgcolor="#396B9C" >
<tr>
<td><center>
<!-- *** START APPLET CODE *** --><center><div id="app"><div id="theapp"><APPLET NAME='DigiChat' CODEBASE='http://67.19.116.210/DigiChat/DigiClasses/'
CODE='com.diginet.d
to 125 as shown, so that it will already be near to its intended size once the app does arrive. Again, just a judgement call.
Rick777
01-25-2009, 07:43 PM
Thank you again.
I have very little knowledge of html. Some of the pages started with Navigator Gold, and Communicator. </div>
I added that back in as I thought it was extra at first, as the page worked.
I took your suggestion for the table.
I was worried about the google code where it was to, but so far no complaints from them. The solution I had for that was a table for the ad code and the applet made on NVU, but that moved over the ad code to where I wanted it when the applet loaded. I figured google would frown on that. I still have my fingers crossed with this one. The page no longer hangs waiting for the applet to load. We are very happy. I am not the best person to improve our pages. Always looking for solutions, but we do not have much right now to improve our pages.
This is a great site. You guys have both been very helpful.
Rick
jscheuer1
01-25-2009, 08:58 PM
It's actually a bit funny what happens with the Google ad code. It must be that the Google scripts create their little ad element that they populate remotely anyway. Then our script takes away the element and puts it back. It also takes away the Google scripts and puts them back, but since scripts added after page load don't run, it harms nothing.
On the two </div> tags, it's just a matter of we opened to div's:
<div id="app"><div id="theapp"><APPLET NAM . . .
in front of the applet, so we must close them both afterward.
Rick777
01-26-2009, 01:58 AM
Thanks you for the help, it helps me to undersand some more about codes for pages.
This looks to be best pace for coding help. :)
Rick
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.