Changes

Jump to: navigation, search

Embedding JavaScript into Web pages

650 bytes added, 19:41, 9 April 2007
no edit summary
* '''type''' - indicates to the browser the type of content contained within the ''<script>'' body. This is typically be set to "text/javascript".
 
A typical use of the ''<script>'' element when embedding the script directly into an HTML file might appear as follows:
 
<pre>
<script type="text/javascript">
// JavaScript code goes here
</script>
</pre>
 
An example of using an external file to contain the JavaScript is as follows:
 
<pre>
<script src="/j-scripts/myjscript.js" type="text/javascript">
</script>
</pre>
 
The above example instructs the browser to load the JavaScript from the ''myjscript.js'' file located on the /j-scripts sub-directory of the local web server. It is possible to specify any valid URL here so this could be a file located on any accessible web server if required.

Navigation menu