4

somebody can answer me why occur this problem?

With the following code my site only works in Chrome, on IE7/8 and Firefox show me only the background:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Site Title</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js" />
<script type="text/javascript" src="js/functions.js" />
</head>
...

And with this code works in Chrome, IE7/8 and Firefox:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CSite Title</title>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/functions.js"></script>
</head>
...

Viewing the code that don't works in Firebug I see that the file 'functions.js' is not called, I don't understand, why don't works with "<script />" and with "<script></script>" works?

0

4 Answers 4

12

from this ticket (Why don't self-closing script tags work?)

(please note that in the referenced ticket the accepted answer is not actually correct)

Note that IE does not support XHTML parsing. Even if you use an XML declaration and/or an XHTML doctype, IE still parses the document as plain HTML. And in plain HTML, the self-closing syntax is not supported. The trailing slash is just ignored, you have to use an explicit closing tag.

Even browsers with support for XHTML parsing will still parse the document as HTML unless you serve the document with a xml mime type. But in that case IE will not display the document at all!

Sign up to request clarification or add additional context in comments.

2 Comments

Note that the accepted answer on the other question is in fact wrong – or at least it’s not the reason for this behaviour.
yeah, should have pointed that out. the answer i quoted was not actually the accepted answer.
4

Because <script> tag MUST have a closing tag in HTML4

Another source for information: XHTML - Is writing self closing tags for elements not traditionally empty bad practise?

Comments

2

The HTML specification requires that you have an end tag for a script element. The former is not valid HTML, while the latter is.

Comments

1

Closing the tags I think is best viewed in code and also I think a good practice. If you follow this tip will no longer have such problems.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.