Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts

    making a js file run fron ONLOAD..

    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...
    <marquee>thanks</marquee>

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Chris..

    May be this will be helpful:

    Code:
    <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.
    Last edited by smalldog; 05-12-2007 at 02:19 PM.
    Forum for webmasters and developers
    http://www.htmlfrenzy.com
    Are you an IT expert? Join our Reward system
    www.htmlfrenzy.com/reward-system.php

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,608
    Thanks
    0
    Thanked 645 Times in 635 Posts
    That is 20th Century JavaScript.

    The 21st Century version is:

    Code:
    <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>
    }
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •