Welcome to WebmasterWorld Guest from 54.145.176.120

Forum Moderators: open

Message Too Old, No Replies

Javascript halts html gifs

Help

   
5:55 am on Jul 22, 2003 (gmt 0)

10+ Year Member



Hi,

I have written an applet that calls a javascript function. Everything works successfully but once I have called the javascript function all of the animated graphics on the html page stop moving.

How can I fix this?

2:04 pm on Jul 22, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld mocca409,

This is a fun one. Here is a thread that will help you understand the problem:
[webmasterworld.com...]

Can you use return false on the function call of the applet? I would assume you could in the end of the function you are calling.

12:00 am on Jul 25, 2003 (gmt 0)

10+ Year Member



Not sure that I tried to use this properly. In my applet code I have the following:

try{
getAppletContext().showDocument( new URL(( "javascript:scrollPage()")));

}catch(java.net.MalformedURLException pl){
//do something here
}

In my html code I have

<script language = "JavaScript">
str = '<OBJECT classid = clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"';
function scrollPage(){
window.scrollTo(0,0);
}
</script>

How would I implement the above suggestion into this?

1:28 pm on Jul 26, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I would try it here although I am really not sure if it will work the way you have your applet set up.

str = '<OBJECT classid = clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"';
function scrollPage(){
window.scrollTo(0,0);
return false;
}

11:22 pm on Jul 27, 2003 (gmt 0)

10+ Year Member



Unfortunately I have already tried this. As a result "false" was written on the html page.

Any other ideas?

8:19 am on Jul 28, 2003 (gmt 0)

10+ Year Member



Loonnng time ago since I was using Applets but I think the problem lies with

new URL(( "javascript:scrollPage()"))

the browser evaluates the 'new url' and 'refreshes' the page, so the page looses focus for a moment and the gifs stop.

You could give this a shot

import netscape.javascript.JSObject;
...
public void callJS(String jsFunction)
{
JSObject myHTMLDoc;
myHTMLDoc = JSObject.getWindow(this);
myHTMLDoc.eval("jsFunction";)
}

or just
import netscape.javascript.JSObject;
...
public void scrollIt()
{
JSObject myHTMLDoc;
myHTMLDoc = JSObject.getWindow(this);
myHTMLDoc.eval("scrollPage();");
}

10:49 pm on Jul 28, 2003 (gmt 0)

10+ Year Member



This still seems to have frozen the gifs. Don't suppose you have any more ideas?
10:21 am on Jul 30, 2003 (gmt 0)

10+ Year Member



A fudge would be add a name attribute to the image tags

<img name="ani_image1" src="ani_image1.gif"

then set an onfocus window event to 'reload' the images, (may already be in cached)

<SCRIPT language="JavaScript">
<!--

function reloadims()
{
document.ani_image1.src = "ani_image1.gif";
// more animated gifs here
}
window.onfocus = reloadims;

//-->
</SCRIPT>

10:23 pm on Jul 30, 2003 (gmt 0)

10+ Year Member



My html now contains

<script language = "JavaScript">
str = '<OBJECT classid = clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"';
function scrollPage(){
window.scrollTo(0,0);
}
function reloadims()
{
document.3d_ball.src = "3d_ball.gif";
}
window.onfocus = reloadims();
</script>

But when I run it, I receive the following error and the gifs are all still frozen.

Line 1
Char 1
Error Object Expected

Any ideas?

1:06 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



window.onfocus = reloadims();
is incorrect

Also probably not best to start the image name with a number something to do with W3 standards. (!)

What does the str assignment do? Doesn't look valid from here- two ' and one "?

try renaming your image to three_d_ball and doing

<script language = "JavaScript">
//str = '<OBJECT classid = clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"';
function scrollPage(){
window.scrollTo(0,0);
}
function reloadims()
{
document.three_d_ball.src = "3d_ball.gif";
}
window.onfocus = reloadims;
</script>

Sticky me the url when your done. I'm nosey.

2:09 am on Aug 5, 2003 (gmt 0)

10+ Year Member



Unfortunately its still not working. I now get the error

'document.three_d_ball' is null or not an object'

I would love to post the page URL for you but its behind a firewall within an Internal LAN, but when its working I could email you a "PrintScreen" of it.

9:35 am on Aug 5, 2003 (gmt 0)

10+ Year Member



I guess the browser is trying to execute the onFocus window event handler but it can't find the image.

It's either
There isn't a name attribute to the image tag?
-
<img name=three_d_ball src= ....

Or
The pointer to the named image is null because it hasn't been declared.
-
you need to insert the <script> after the image. Probably best to put it just before the </body>

10:37 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



You were right I didn't have a name declared for the image. The graphics become animated again (great work, thanks) but unfortunately this only occurs when a user clicks on the screen on a space other than the applet. The problem is the applet is pretty much the whole screen. Is there a command I can use to call reloadims when a user clicks anywhere on the screen, or when they click the scroll bar?
7:34 am on Aug 6, 2003 (gmt 0)

10+ Year Member



The window also has other event handlers, you could do
window.onscroll = reloadims;
document.onmousedown=reloadims;
window.onmousedown=reloadims;

I suspect that if the user clicks within the applet area the event will not bubble up to the window, so you may have to implement a Java mousedown within the applet to call the reloadims();

A possible fudge to avoid all this is just to

function reloadims()
{
document.three_d_ball.src = "3d_ball.gif";
}
setInterval("reloadims()",250);

which calls reloadims 4 times a second. Fudgetaskic!

10:20 pm on Aug 6, 2003 (gmt 0)

10+ Year Member



I love the fudge. I'm going with that, and it works really well. Thanks so much for all of your help. I'm going to try and send you a sticky mail of the page now.

Its not much to look at, as its all inbuilt into the applet.

Thanks again

 

Featured Threads

Hot Threads This Week

Hot Threads This Month