Welcome to MSDN Blogs Sign in | Join | Help

SYSK 147: On the Importance of Script Closing Tags

Are the following two lines semantically different?

<script language="javascript" type="text/javascript" src="JScript.js"></script>

<script language="javascript" type="text/javascript" src="JScript.js" />

 

As it turns out (at least in IE 6.0) they are… 

 

The first line with the explicit closing script element, the code works as expected.  However, IE stops processing the document at the <script … /> line, which means that if your html rendering code is below that line, you’ll get a blank page displayed; and if you have the html UI before the script line, you’ll get 'Object expected' error…

 

Try it for yourself:

<head runat="server">

    <title>Test Page</title>      

    <script language="javascript" type="text/javascript" src="JScript.js"></script>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <input id="Text1" type="text" />

            <input id="Button2" type="button" onclick="DisplayText();" value="Press Me" />

        </div>

    </form>

</body>

</html>

 

// JScript File

function DisplayText()

{

    alert(document.getElementById('Text1').value);

}

 

**  Firefox 1.5.0.4 doesn’t seem to “suffer” from this problem.

 

Published Thursday, June 29, 2006 6:38 AM by irenak

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SYSK 147: On the Importance of Script Closing Tags

Thursday, June 29, 2006 4:34 PM by hasanib
does ie7 have this "feature" too?
:)

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker