Embedding JavaScript in HTML page
In this article, you can see the types in which you can write javascript files. At the end of this article, we have a clear understanding of embedding the script files in an HTML document in two ways.
- The script is embedded in HTML document using <script> tag.
- The browser process the script code in the <script> tag.
- The attributes of <script> tag are:
type: The type can be “text/javascript” or “text/vbscript” or “text/ecmascript“.
language: The attribute can have the value as “javascript” or “vbscript“.
src: URL of the script file for embedding used for external script files.
The script can be:
- Inline script / Embedded script
- External script
Inline Script/Embedded Script:
The script is specified in the HTML document using <script> tag in the <head>/<body> tag.
Example:
<html lang="en"> <head> <script language="javascript" type="text/javascript" > document.write("Welcome to CodeSpeedy"); </script> </head> </body> </html>
Output: //inline.jpg
External Script:
The javascript code is written in an external file using the “.js” extension.
a.js document.write("External Script"); document.write("<BR>"); document.write("Welcome to CodeSpeedy");
the script file can be accessed on a webpage using the <script> tag.
<html lang="en"> <head> <script src="a.js" type="text/javascript" > </script> </head> </html>
Leave a Reply