Calling an External Script - HTML

If you have some scripts that you want to use in multiple documents, consider placing the scripts in an external file. You can then use the src attribute of the <script> tag to specify that the script content can be found in that file. For example, suppose you want to include the following script in multiple documents:

function NewWindow(url){
fin=window.open(url,“width=800,height=600,
scrollbars=yes,resizable=yes”);
}

You can place the script in a text file on the server and specify the file’s URL in the appropriate <script> tags’ src attribute. For example, suppose the preceding file was stored in the file scripts.js on the server. Your script tag would then resemble the following:

<script type=“text/javascript” src=“scripts.js”></script>

One major advantage to external script files is that if you need to edit the script, you can edit it in one place—the external file—and the change is effected in all the files that include it.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HTML Topics