checkout here how onload blocked even we use asyn js loading techniques
So here is another solution for same :-)
- create an iframe without setting src to a new URL. This fires onload of the iframe immediately and the whole thing is completely out of the way
- style the iframe to make it invisible
- get the last script tag so far, which is the snippet itself. This is in order to glue the iframe to the snippet that includes it.
- insert the iframe into the page
- get a handle to the document object of the iframe
- write some HTML into that iframe document
- this HTML includes the desired script
var iframe = document.createElement('iframe');
(iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
var where = document.getElementsByTagName('script');
where = where[where.length - 1];
var doc = iframe.contentWindow.document;
'var js = document.createElement(\'script\');'+
'js.src = \''+ url +'\';'+
3. The script (asyncjs1.php) runs is in an iframe, so all document and window references point to the iframe, not the host page.There's an easy solution for that without changing the whole script. Just wrap it in an immediate function and pass the document object the script expects:
document.getElementById('r')... // all fine
4. The script works fine in Opera, but blocks onload. Opera is weird here. Even regular async scripts block DOMContentLoaded which is a shame.
seems below code solves our problem .. try it and let me know the results ...