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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Document.write Problem

    document.write("<script type='text/javascript' src='http://www.website.com/javscript.js'></script>");

    For some reason this will not output correctly. It ouputs

    ");

    Which is the last three characters.

  • #2
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I figured it out. I need to escape the forward slashes

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    You are seeing
    ");

    because the script ends at
    </script>

    and the browser thinks
    ");
    is html
    do it something like this


    document.write("<script type='text/javascript' src='javscript.js'></"+"script>");

  • #4
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    I often use this site for such purposes:

    http://www.stevenolte.com/docwriter.html
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,471
    Thanks
    13
    Thanked 361 Times in 357 Posts
    I wouldn’t use document.write() in this case at all. just put the <script> tag in the HTML. if JavaScript is enabled, the script file is used, if not (which should be quite a low percentage of users), then it’s not used.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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