WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
12131
Onload not working for loading scripts dynamically.
https://bugs.webkit.org/show_bug.cgi?id=12131
Summary
Onload not working for loading scripts dynamically.
Jeremy Nicoll
Reported
2007-01-05 12:55:47 PST
In developing AJAX scripts, it is important to know if or when a javascript file has loaded. Unfortunately there is no way to tell in Javascript if a specific file has loaded in Safari. In Opera and Firefox one can use the "onload" handler and in Internet Explorer one can use the "onreadystatechange" handler to call a function that can serve this purpose. Both of these methods fail in Safari however. Here are two different ways to attach events (cross browser, generally), both of which fail in Safari: --------------------- First Way --------------------- script_object = document.createElement('script'); sEventType = 'load'; fnHandler = listener; script_object.src = 'some_file.js'; if (script_object.addEventListener) { script_object.addEventListener('load', listener, false); } else if (script_object.attachEvent) { script_object.attachEvent('onload', listener); } else { script_object['onload'] = fnHandler; } document.getElementsByTagName("head")[0].appendChild(script_object); --------------------- Second Way --------------------- script_object = document.createElement('script'); script_object.onreadystatechange = listener; script_object.onload = listener; document.getElementsByTagName("head")[0].appendChild(script_object); I expect Safari to call the listener function (named listener in these examples), but nothing to this effect happens. This seems to happen in all instances. In my search for a work around to this problem, I have also seen many requests for this type of functionality to be added to CSS files as well as there are times that JavaScript methods will try to modify non-existent CSS properties and cause errors. This would give JavaScript coders a way to check to see if the required files have been loaded.
Attachments
Add attachment
proposed patch, testcase, etc.
David Kilzer (:ddkilzer)
Comment 1
2007-01-05 13:13:35 PST
Jeremy, are you testing on a shipping version of Safari, or a WebKit nightly (
http://nightly.webkit.org/
)? Which version(s) of each have you tried? Note that WebKit nightlies start up your existing Safari with a different WebKit framework, so the "About Safari" box will look the same. Just report the rNNNNN number for the WebKit nightly.
Darin Adler
Comment 2
2008-03-24 18:16:36 PDT
I'm pretty sure that calling setAttribute("onload", fnHandler) will work. Can someone try this?
Jeremy Nicoll
Comment 3
2008-03-24 21:11:46 PDT
Actually, that last bit does not work - however, it looks like addEventListener and script_object.onload = some_function are now working in the latest version of Safari as well as Webkit.
Darin Adler
Comment 4
2008-03-24 21:27:45 PDT
If some things aren't working, we should have a bug report for those things.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug