...

View Full Version : making a js file run fron ONLOAD..



chris_angell
05-12-2007, 12:54 PM
Hello i have a js lightbox script that i am trying to run from onload ?? because when i run it normally i am getting an "operation aborted" message from IE.. but after reading the advice i have been given is to run my JS file from onload to it does not conflict with the other code...

but could anyone tell me the best way to run

<script type="text/javascript" src="js/mootools.js"></script>

from ONLOAD

:) cheers chris...

smalldog
05-12-2007, 02:12 PM
Hi Chris..

May be this will be helpful:



<script>
function Load(){
document.write('<script type="text/javascript" src="js/mootools.js"></script>');
}
</script>

<body onload="Load();">


Better solution probably is, define your Load() function within that external JS.

felgall
05-12-2007, 10:00 PM
That is 20th Century JavaScript.

The 21st Century version is:



<script type="text/javascript">
function addJavascript(jsname) {
var th = document.getElementsByTagName('head')[0];
var s = document.createElement('script');
s.setAttribute('type','text/javascript');
s.setAttribute('src',jsname);
th.appendChild(s);

window.onload = function() {addJavascript('js\/mootools.js');};
</script>

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum