Inserting JavaScript into a Web PageInformation - Put Your Scripts in <head> JS scripts are usually put in the <head> of a document so that they are loaded first. Scripts are enclosed in the <script>, </script> tags. The segment of an HTML page below puts shows the format for inserting JS. <html> Information - Hiding Scripts From Old Browsers Older browsers don't execute JS. Instead, they display the text of the JS on the screen along with your page text. This can be disconcerting to some users. To prevent this from happening, use the JS comment tags to "hide" the JS from old browsers. The comment tags are <!-- and // -->. <html> Information - Scripts Are Executed Before the User Interacts JavaScripts that are in the <head> execute before the user sees the page. The script below calls the alert box which the user sees before he/she sees any text on the web page. <html> Exercise 1 The script above illustrates five things:
1. Open Notepad and type in the script immediately above
Exercise 1 exactly as it is shown. |