SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically insert javascript with IE conditional comment

    ie7.js is a javascript that standardises IE browser.

    The original usage code

    HTML Code:
    <!--[if lt IE 7]>
    <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript"></script>
    <![endif]-->
    How do i insert it dynamically with the Internet Explorer conditional comment into a html file with javascript ?

    The code below actually works but I just do not know how to insert the internet explorer conditional comment
    Code:
    window.onload=function(){
    var script=document.createElement('script');
    script.type="text/javascript";
    script.src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js";
    var head=document.getElementsByTagName('head');
    head[0].appendChild(script);
    }

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var cc= document.createComment('[if lt IE 7]><script src="http://ie7-js.googlecode.com/svn/'version/2.0(beta3)/IE7.js" type="text/javascript"></script><![endif]');
    
    document.getElementsByTagName('head')[0].appendChild(cc);

    The document.documentElement.innerHTML returns-

    <!--[if lt IE 7]>
    <script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE7.js" type="text/javascript">
    </script>
    <![endif]-->


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
  •