Results 1 to 3 of 3

Thread: Include .js files if not already included.

  1. #1
    Join Date
    Mar 2010

    Include .js files if not already included.

    I am having a bit of difficulty with this issue. Server side i am looking to see if the product id variable is set, and if so then include jquery.js, since it is only required for a few features on those pages.
    However, i am implementing a nice drop down menu which uses some javascript and jquery as a fallback for IE6. The problem is that if i am using IE6, the conditional statement in the html source is being executed by it, and thus the jquery.js is being included by it at that time... This works on all pages BUT the products page where i am also including jquery.js.
    What happens is that the conditional statement is executed causing jquery to be included, but when it is then included a second time by the server side code, the drop down menu stops working. The only way i can figure out how to fix this issue is to only include the jquery.js if it hasn't already been included, which i assume itself would need to be client side.
    So, does anyone have any ideas on how to only include a .js file if it hasn't already been included?

    Thanks in advance

  2. #2
    Join Date
    May 2003
    Between Baltimore and DC
    One dirty idea

    <!--[if IE 6]>
      if(typeof jQuery === "undefined"){
        document.write("<scr" + "ipt src='jquery.js'></scr" + "ipt>");
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  3. #3
    Join Date
    Mar 2010
    Excellent, thanks, worked perfectly.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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