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.