Find more freelance jobs
|
Scripts in the head section: Scripts to be executed when they are called, or when an event is triggered, goes in the head section. When you place a script in the head section, you will ensure that the script is loaded before anyone uses it. <html> <head> <script language="JavaScript"> some statements </script> </head> Scripts in the body section: Scripts to be executed when the page loads, goes in the body section. When you place a script in the body section it generates the content of the page. <html> <head> </head> <body> <script language="JavaScript"> some statements </script> </body> Scripts in both the body and the head section: You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section. <html> <head> <script language="JavaScript"> some statements </script> </head> <body> <script language="JavaScript"> some statements </script> </body> How to use external script Sometimes you might want to run the same script on several pages, without writing the script on each and every page. To simplify this you can write the script in a external file, and save it with a .js file extension. Like this: document.write("This script is external") Save the external file as xxx.js -The filename can not contain more than 8 letters -The external script can not contain the <script> tag Now you can call this script, using the "src" attribute, from any of your pages: <html> <head> </head> |