Forum Moderators: open

Message Too Old, No Replies

Self-closing script tag and page doesn't render in IE7

         

stef25

3:22 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



I have a simple php page which renders fine in all PC browsers except IE7 and IE6. On Mac it doesnt render in FF3 Beta. In all browsers including those, view source shows the full page code.

I have some php session and query code at the top but echo "test" gets printed everywhere, so i dont think the problem is in the php code.

On FF3 Beta Mac source view, color coding in the source stops after this line. "test" also doesnt get printed out anymore after this line in IE PC but plcaed higher up in the head section it does.

<script src="js/jquery-1.2.2.pack.js" type="text/javascript" />

W3C shows a few trivial non validation issues but nothing related to that line. Firebug shows no errors at all and im in standards compliance mode.

the issue is def to do with the line above, but thats about as far as i get. Anyone?

[edited by: tedster at 4:18 pm (utc) on Mar. 30, 2008]

stef25

3:42 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



ok ... after adding a closing tag to the last js file, things are now loading. strangely enough the color coding in Notepad++ also came back because of this. (I just started using Notepad++ so wasnt familiar with its color coding yet).

Obviously the self closing tag created a problem that both IE7 and Notepad++ recognised, but what is that problem? Afaik, using a closing tag on a simple JS link is not required if it self closes?

Problem is solved but I'd love to find out the reasoning behind this.

tedster

4:05 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I understand it, self-closing tags are only appropriate for elements that are always empty - elements such as br, img, hr and so on. When you use a script element to call an external script, it only contains attributes and is therefore apparently empty. But a script element can, and often does, contain content when it declares an inline script. So <script> should be closed with a proper </script> end tag and not self-closed.

stef25

4:16 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



afaik using self closing tags does pass W3C xhtml validation ... should it not?

tedster

4:26 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That may be - it's a pretty academic question and I'm more of a pragmatist. If source code breaks a major browser, I don't use it. We have some members who are excellent on the theoretical side - I hope one of them can add some insight.

By the way, I don't personally use XHTML right now, although many of my clients do. Here's a very important thread on that topic:

Why most of us should NOT use XHTML [webmasterworld.com]

stef25

4:38 pm on Mar 30, 2008 (gmt 0)

10+ Year Member



im familiar with that thread :-) i'm also more of a pragmatist

just find it a little strange that an error in my xhtml syntax which majorly breaks the page in IE7 does pass as valid.

no big deal though, problem is solved and i learnt something

g1smd

6:30 pm on Mar 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Self-closing a tag, and then using an HTML 4.01 DOCTYPE can also cause some wierd issues.

encyclo

12:00 am on Mar 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



afaik using self closing tags does pass W3C xhtml validation

Yes, it's perfectly valid XHTML... however it's invalid HTML (where

script
requires a closing tag [htmlhelp.com]). The unexpected result is a combination of two myths: the first myth is that XHTML syntax is compatible with HTML syntax, which is not the case as you have demonstrated. The second myth is that IE supports XHTML syntax.

You were serving the page as HTML (mime type

text/html
) so the syntax you used validates as XHTML, but is broken HTML. IE only supports XHTML to the extent that only HTML-compatible markup is possible. Trailing slashes are simply discarded by the browser as unknown (erroneous) attributes, and as such the
script
element in your first example is seen by the browser as being unclosed. The fact that the page doesn't display with your example markup is "correct" handling when dealing with HTML and not XHTML.

tedster

2:10 am on Mar 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks encyclo - that was exactly the insight we needed. You made things crystal clear for me.