ISMA309


Embedding and Including Javascript

by Haig. Average Reading Time: less than a minute.

Javascript is a programming language that is usually included or embedded into HTML files to add behaviours that HTML is not capable of.

Embedding

Here’s a simple example of how javascript is embedded in an HTML page:

	
		
			This is a JavaScript example
			
		
		
			Hey there!
		
	


Usually, JavaScript code starts with the tag

.

The javascript code is commonly placed between Head tags but sometimes it's embedded in the Body tags, like this:

	
		
		
			
		
	

Why do we place JavaScript code inside comment fields ? It’s for ensuring that the Script is not displayed by old browsers that do not support JavaScript. This is optional, but considered good practice. The LANGUAGE attribute also is optional, but recommended. You may specify a particular version of JavaScript:

	

For example, shown below is the code of the external file hello.js:

	document.write("Hello World!")

The external file is simply a text file containing JavaScript code with the file name extension “.js”.

Next up: Write and Writeln

No comments on ‘Embedding and Including Javascript’

Leave a Reply