SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Conditional include javascript

    Hi..

    I'm a bit of a newbie to javascript, but liking what it can do these days.

    Was wondering, is there a way to conditionally include a javascript? kindof like via an xmlhttprequest? So you only load the necessary files when you actually need them?

    Also, if someone has javascript turned off in their browser, does it still load external javascript files? (i guess IE and FF do different things there)

    Thanks

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work:

    Code:
    function jsAppend(js_file)
    {
      js_script = document.createElement('script');
      js_script.type = "text/javascript";
      js_script.src = js_file;
      document.getElementsByTagName('head')[0].appendChild(js_script);
    }

  3. #3
    SitePoint Guru toasti's Avatar
    Join Date
    Feb 2004
    Location
    Grahamstown
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awesome. thanks.


Bookmarks

Posting Permissions

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