[Webkit-unassigned] [Bug 12131] New: Onload not working for loading scripts dynamically.
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri Jan 5 12:55:48 PST 2007
http://bugs.webkit.org/show_bug.cgi?id=12131
Summary: Onload not working for loading scripts dynamically.
Product: WebKit
Version: 420+ (nightly)
Platform: Macintosh
URL: http://www.jsrepository.com
OS/Version: Mac OS X 10.4
Status: UNCONFIRMED
Severity: Normal
Priority: P2
Component: WebCore JavaScript
AssignedTo: webkit-unassigned at lists.webkit.org
ReportedBy: jnicoll at seemysites.net
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.
--
Configure bugmail: http://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the webkit-unassigned
mailing list