FireFox <script> tag bug

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • labmonkey111
    New Member
    • Sep 2008
    • 44

    FireFox <script> tag bug

    I'm having trouble with the following code:

    Code:
    <SCRIPT>
    	<!--
    	if (navigator.appName == 'Microsoft Internet Explorer') {
    		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"templates/94076/menu.css\" media=\"screen, print\" />");
    		document.write("<script src=\"templates/94076/menu.js\" language=\"javascript\" type=\"text/javascript\"></script>");
    	} else {
    		document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"templates/94076/menu-ns.css\" media=\"screen, print\" />");
    	}
    	//-->
    </SCRIPT>
    For some reason in FireFox, the "</script>" in the string on the 5th line is being seen and the end of the first <script>, and not as part of the string. So firefox is displaying:

    Code:
    "); } else { document.write(""); } //-->
    at the top of the page. IE7 seems to handle it ok. My main problem here is that I have no control over this code, it is added to the code by a ecommerce site. So I have no idea what to do about it. Does any one have any ideas why FireFox is seeing this incorrectly? Any suggestions about how I may go about fixing this? This is for this site, but I have to keep it reverted to the old working version so this will only show up while I'm working on it during the day.

    Any help will be greatly appreciated.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Sigh.

    Where have you learned this?

    Get with the times, you have to specify a type attribute to the script element, which, might I add, should be lower-case as should all element names.

    Mark.

    Comment

    • labmonkey111
      New Member
      • Sep 2008
      • 44

      #3
      As I said, I have no control over this code, it is inserted by the e-commerce site into the template I'm designing. I'm well aware that the code sucks, but I can't do anything about it.

      Comment

      • drhowarddrfine
        Recognized Expert Expert
        • Sep 2006
        • 7434

        #4
        You are using xhtml end tags, />, but declaring html. Remove the slashes. Sometimes browsers will stop processing at that point.

        Firefox has no issues with <script>

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          You'll need to escape or expand the end script tag, e,g.
          Code:
          document.write("<script src=\"templates/94076/menu.js\" type=\"text/javascript\"><\/script>");
          // altenatively
          document.write("<script src=\"templates/94076/menu.js\" type=\"text/javascript\"></scr" + "ipt>");

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by labmonkey111
            My main problem here is that I have no control over this code, it is added to the code by a ecommerce site. So I have no idea what to do about it.
            Why is a eCommerce site adding stuff to your page?
            Can't you just write a proper version of this code and use that in stead of the mess this eCommerce site is giving you?

            If there is no other way than to have this mess forced upon you, I can not see how you can fix it.
            You would have to contact the people responsible for it and have them fix it.

            Comment

            • labmonkey111
              New Member
              • Sep 2008
              • 44

              #7
              Originally posted by Atli
              Why is a eCommerce site adding stuff to your page?
              Can't you just write a proper version of this code and use that in stead of the mess this eCommerce site is giving you?
              This was just a template that the site uses so the eCommerce page will look the same as the real site. After fighting with it for hours and fixing tons of other bugs and display issues, I did manage to find out that I was using the wrong doctype. The first person to work on this project used Dreamweaver and apparently it guessed wrong. The original template had no doctype, so as soon as I removed it altogether it worked ok. I hate not using one but it works now and I don't care, this project took way too long (they're gonna flip when they see the bill!)

              Thanks for all the input.

              Comment

              • Atli
                Recognized Expert Expert
                • Nov 2006
                • 5062

                #8
                Ok. Glad you got it to work.

                I should point out tho, if only for future reference, that by leaving out the doctype you aren't really fixing the problem. Firefox simply switches out of standards-compliance mode and into quirks-mode, which is made to allow a certain amount of errors and buggy markup. It won't render you pages correctly in quirks-mode, but if you markup is buggy already, it might *seem* less buggy.

                Comment

                Working...