aspose file tools*
The moose likes Applets and the fly likes Javascript/Applet problem in certain versions of Safari Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Javascript/Applet problem in certain versions of Safari" Watch "Javascript/Applet problem in certain versions of Safari" New topic
Author

Javascript/Applet problem in certain versions of Safari

Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
I have a JSP page that contains the following code (among a lot of other stuff):



The startLewisSketch() method resides in ../js/appletStart.js. The page works by loading the LewisSketch applet, and then, after it is loaded, the page is supposed to call the loadMol() method, which calls LewisSketch and sets its value.

All of this works fine in the version of Safari that I am running (5.0.6, MacOS 10.5.8), but sometimes a Javascript error occurs on more recent versions of Safari and MacOS:



When this error occurs, the methods subsequent to loadMol() in the body onload property do not run.

It appears to me that there's a problem with the timing of the applet load and the body onload in some versions of Safari. Any ideas how I can solve the problem or work around it?
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Bob Grossman wrote:
..The startLewisSketch() method resides in ../js/appletStart.js. The page works by loading the LewisSketch applet, and then, after it is loaded, the page is supposed to call the loadMol() method, which calls LewisSketch and sets its value.
...
When this error occurs, the methods subsequent to loadMol() in the body onload property do not run.

It appears to me that there's a problem with the timing of the applet load and the body onload in some versions of Safari. Any ideas how I can solve the problem or work around it?


Note what the W3C has to say about the onload event.

W3C wrote:
onload = script [CT]
The onload event occurs when the user agent finishes loading a window or all frames within a FRAMESET. This attribute may be used with BODY and FRAMESET elements.


Now, do you notice the bit where it doesn't mention say.. external stylesheets, scripts, images or applets? The event fires when the HTML content of the URL is finished loading, not the rest of it that is referenced by that HTML.

As to fixing the problem. Put a statement at the end of the applet init() or start() that calls the JS function to load the data. Then you know the applet is ready to accept data!


Andrew Thompson
http://pscode.org/
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
Thanks for your help, Andrew. Instead of using onload, I now simply pass the start-up value to startMSketch(), which passes it as a parameter to the applet, which then initializes itself with the value. That way I don't have to have the applet calling back to the Javascript. So now I have,



and js/appletStart.js contains:



and the LewisSketch applet init() method contains:



and LsUtils.convertParamValue is:


Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
Bob Grossman wrote:..Instead of using onload, I now simply ..


Does that mean the problem is now solved? I'm not clear on what your saying and did not spend the time trawling through those (very wide) code examples.
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
I can't tell whether the problem is solved, because I don't have a browser/system combination that manifested the problem in the first place. I've asked my friend to check it, but he hasn't done so yet. But I am no longer relying on onload to load the value into the applet, and I am instead loading the applet during its init() method, and the page is still working in my browser, so I think the problem should be solved.
Bob Grossman
Ranch Hand

Joined: Dec 18, 2008
Posts: 69
Hi,

The problem has indeed been solved.

But I now have the same problem with a different applet, and this time, I don't have control over the applet code (it's third-party).

Is there a way to wait for an applet to be loaded before executing some Javascript code?

I tried the following, but no joy:



-- Bob
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Javascript/Applet problem in certain versions of Safari