homepage Welcome to WebmasterWorld Guest from 54.226.10.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript halts html gifs
Help
mocca409

10+ Year Member



 
Msg#: 505 posted 5:55 am on Jul 22, 2003 (gmt 0)

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?

 

korkus2000

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



 
Msg#: 505 posted 2:04 pm on Jul 22, 2003 (gmt 0)

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.

mocca409

10+ Year Member



 
Msg#: 505 posted 12:00 am on Jul 25, 2003 (gmt 0)

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?

korkus2000

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



 
Msg#: 505 posted 1:28 pm on Jul 26, 2003 (gmt 0)

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;
}

mocca409

10+ Year Member



 
Msg#: 505 posted 11:22 pm on Jul 27, 2003 (gmt 0)

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

Any other ideas?

HocusPocus

10+ Year Member



 
Msg#: 505 posted 8:19 am on Jul 28, 2003 (gmt 0)

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();");
}

mocca409

10+ Year Member



 
Msg#: 505 posted 10:49 pm on Jul 28, 2003 (gmt 0)

This still seems to have frozen the gifs. Don't suppose you have any more ideas?

HocusPocus

10+ Year Member



 
Msg#: 505 posted 10:21 am on Jul 30, 2003 (gmt 0)

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>

mocca409

10+ Year Member



 
Msg#: 505 posted 10:23 pm on Jul 30, 2003 (gmt 0)

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?

HocusPocus

10+ Year Member



 
Msg#: 505 posted 1:06 pm on Jul 31, 2003 (gmt 0)

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.

mocca409

10+ Year Member



 
Msg#: 505 posted 2:09 am on Aug 5, 2003 (gmt 0)

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.

HocusPocus

10+ Year Member



 
Msg#: 505 posted 9:35 am on Aug 5, 2003 (gmt 0)

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>

mocca409

10+ Year Member



 
Msg#: 505 posted 10:37 pm on Aug 5, 2003 (gmt 0)

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?

HocusPocus

10+ Year Member



 
Msg#: 505 posted 7:34 am on Aug 6, 2003 (gmt 0)

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!

mocca409

10+ Year Member



 
Msg#: 505 posted 10:20 pm on Aug 6, 2003 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved