To use the same script on multiple pages, you should
Listing shows the reference to the external file.
Listing: External Script Reference<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
(the rest of your HTML page goes here)
Adding the src attribute to the <script> tag tells the browser to look for that external file in the specified path. The resulting Web pages look and act like the scripts are in the header or body of the page’s script tags, though the script is in the external .js file.
If you use a script on only one page, it’s often easier simply to put the script on the page in a body or header script.
If you have multiple external .js files, you can use any or all of them on any HTML page. Just include multiple <script> references on the page. It’s perfectly okay for a page to include multiple scripts and to both refer to external .js files and include its own scripts inside <script> tags.
When you have multiple <script> tags defined in your Web page, the browser processes them in the order in which they are declared. If, for some reason, you have an external .js file that conflicts with a script inside a <script> tag, the last one defined wins.
Note that the contents of the .js file shown in Listing could be copied directly into a <script> tag and function identically.
HTML 4 Related Interview Questions
|XML Interview Questions||HTML 4 Interview Questions|
|HTML Interview Questions||HTML 5 Interview Questions|
|HTML DOM Interview Questions||Java Interview Questions|
|CSS Interview Questions||Java Abstraction Interview Questions|
|Dynamic HTML Interview Questions||XHTML Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.