PRB: SRC Attribute of the <SCRIPT> tag

Last reviewed: October 29, 1997
Article ID: Q172924
The information in this article applies to:
  • Microsoft Internet Explorer (Programming), versions 3.0, 3.01

SYMPTOMS

The SRC attribute of the <SCRIPT> tag lets you specify a file as the JavaScript source, rather than embedding the JavaScript in the HTML. Here's an example:

   <HEAD>
   <TITLE>My Page</TITLE>
   <SCRIPT SRC="common.js">
   ...
   </SCRIPT>
   </HEAD>
   <BODY>
   ...

This attribute is especially useful for sharing functions among many different pages. Unfortunately, Internet Explorer 3.x does not support it.

STATUS

Internet Explorer 4.0 supports the SRC attribute of the <SCRIPT> tag.

MORE INFORMATION

Steps to Reproduce Behavior

   =====HTML File=====
   <HTML>
   <HEAD>
   <TITLE>SRC Sample</TITLE>
   </HEAD>
   <BODY>
   <H3> SRC Example <H3><HR>
   <FORM>
   <SCRIPT LANGUAGE="Javascript" SRC="script.js">
   document.write("If you see this text, your browser does not support the
   SRC attribute of the &ltSCRIPT&gt tag.");
   </SCRIPT>
   </FORM>
   </BODY>
   </HTML>

   =====script.js=====
   document.write("Hello from inside script.js");

   ===================

NOTE: External JavaScript files cannot contain any HTML tags; they must contain only JavaScript statements and function definitions.

External JavaScript files should have the file name suffix .js, and the server must map the .js suffix to the MIME type "application/x-javascript," which the server sends back in the HTTP header. To map the suffix to the MIME type, add "application/x-javascript,js,5" to the server's Registry key HKEY_LOCAL_MACHINE/System/ControlSet001/Services/InetInfo/Parameter/MimeMap and then restart the server.

If the server does not map the .js filename suffix to "application/x- javascript" MIME type, the browser will not load the JavaScript file specified by the SRC attribute properly.

Keywords          : vbObjMdIIE kbcode
Version           : WINDOWS:3.0,3.01
Platform          : WINDOWS
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.