|
|
Embedding JavaScript in HTML - Online JavaScript lessons for BeginnersThe first Javascript lesson for the beginnerAs I mentioned in the introduction, these online javascript lessons have been developed keeping the beginner in mind. Hence we start with the basics - how to embed JavaScript in an HTML document. Since JavaScript started off as a client-side language (it is now extensive used in Microsoft's ASP technology for server-side scripting), we need to understand how we can include it on web pages so that browsers (clients) can read it. JavaScript works with HTML to bring interactivity to otherwise static documents and can be embedded inside HTML documents in three ways:
Using the <SCRIPT> tags <HTML> <HEAD> <TITLE>Page title</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT"> <!-- some javascript code //--> </SCRIPT> </BODY> </HTML> The LANGUAGE attribute explicitly informs the browser that the enclosed code is JavaScript. The TYPE specifies that the code is in TEXT format. JavaScript code inside HTML tags
<A HREF="http://www.webdevelopersnotes.com"
onmouseover="alert('Go back to Home Page')">
Home Page</A>
Here we have an anchor tag that surrounds some text ('Home page'). Don't worry if you can't understand the code (you are not supposed to at this stage). Just take a note of how the code is embedded inside the anchor tag. onmouseover is an event handler and as its name suggests, it manages a mouse over action. In this case, onmouseover event handler triggers some response whenever the user moves the mouse cursor over the text enclosed between the anchor tags. Placing JavaScript code in another file <SCRIPT LANGUAGE="JAVASCRIPT" SRC="mycode.js" TYPE="TEXT/JAVASCRIPT"> <!-- //--> </SCRIPT> Note that the external file containing the JavaScript code has .js extension. It is included in the HTML document through the SRC attribute that takes the URL of the file as its value. Equipped with this basic knowledge, let's move towards creating your first script.
Page contents: Online javascript lessons for beginners - embedding javascript in html - javascript and html
Page URL: http://www.webdevelopersnotes.com/tutorials/javascript/ embedding_javascript_html_web_pages.php3
|
|