civciv — 2007-03-02T04:15:43-05:00 — #1
<script src='xxx.js' onload='alert("hello")'></script>
It isn't working in internet explorer, how can i fix it?
ceeb — 2007-03-02T05:05:06-05:00 — #2
Do you really, really need to do that? If you want to ensure all scripts have loaded, you'd be better off using window.onload.
If you absolutely must do it, then forget the onload and just have alert("hello"); (or whatever) at the end of your xxx.js script.
mrhoo — 2007-03-02T10:54:37-05:00 — #3
civciv — 2007-03-02T13:40:54-05:00 — #4
Do you really, really need to do that?
Yes, i use "script" element in my ajax works and i need an "onComplete" property for this element.
jimfraser — 2007-03-02T14:41:47-05:00 — #5
In IE it looks like onload is broken for the <script> tag.
pepejeria — 2007-03-02T16:38:39-05:00 — #6
The only cross-browser solution for is what ceeb suggested. Take it from there. Maybe have a function that the loaded external scripts notify or whatever.
ceeb — 2007-03-03T02:59:25-05:00 — #7
OK, since this is for AJAX, I assume you're loading the script by adding a new <script> tag to the DOM in the HTML <head>? I guess that you're also sending data to that script to fetch some results? e.g.
If so, then you could append a callback argument to this data which contains the name of the function you need to run once the script has loaded, e.g.
Your server side script would then put that call at the end of the code, e.g.
// ... do work and output JS code ...
// run callback function
$callback = $_GET['callback'];
if ($callback != '') echo "$callback()\