Hi again, Here is some beta code I've put together that loads a script after page load. It has these features : - cross-domain - Has a callback (onload) parameter - Tested on FF2, Safari2 & Opera 9.10 (should also work on IE5+)
It could have many uses, including parsing the external scripts in an ajax.updater for instance. Current issues: - there is an iframe hack for the callback with safari, hence 2 queries are sent out. - opera appears to load the file synchronously Any thoughts/help/patches/ideas on that code? //used to insert a script after page load var Prototype.insertScript = function(url,callback) { var script = document.createElement('script'); script.type = 'text/javascript'; script.charset="utf-8"; script.defer=true; var stateChangedCallback = function() { if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete') return; script.onreadystatechange = script.onload = null; if (callback) callback(); $(script).remove(); }; script.onload = script.onreadystatechange = stateChangedCallback; script.src=url; //Opera 9.10 appears to load the script synchronously. execution could hang here a while. document.getElementsByTagName('head').item(0).appendChild(script); //safari iframe hack. // warning, it has one main issue, the request will be issued two times. // should only be used for static files. if (Prototype.Browser.WebKit && callback) { var iframe = document.createElement('iframe'); iframe.style.width="0px"; iframe.style.height="0px"; iframe.setAttribute("src",url); document.getElementsByTagName('body').item(0).appendChild(iframe); iframe.onload = function() { stateChangedCallback(); $(iframe).remove(); } } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---