Your host:
Stephen Chapman
Stephen Chapman

How do you add a Javascript to your page?

Javascripts can be added to a web page in several different ways. They can be added into the head section of the page in which case any executable statements will be executed before the page is loaded. They can be added to the body of the page in which case statements will execute as the page is loading. Javascript within the body of the document may also call functions contained within the head of the document in which case the function will be loaded before the page and executed while the page is loading.

Javascript can be embedded into the page itself in which case it will be preceded by a <script type="text/javascript" language="JavaScript"> statement and followed by a </script> statement. Javascript so contained is usually also contained within an HTML comment <!-- --> so that older browsers that do not recognise the script commands do not attempt to process the code as HTML. Note that commenting out Javascript in this way is not supported by XHTML.

Javascript can also be loaded separately from the page and linked to it. In this case the Javascript should be loaded to the website in a .js file. It is then referenced in the page's HTML by a <script type="text/javascript" src="filename.js"></script> statement (where filename is the name that the javascript was saved as). This has the advantage that the same Javascript can be referenced from multiple pages.

Javascript event handlers can be embedded directly into your HTML code.

go to top

Add to del.icio.us

Credit Card Consolidation - Credit Counseling - Remortgage - Car Insurance