• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Javascript/Applet problem in certain versions of Safari

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 77
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Bob Grossman
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic