Embedding JavaScript into a HTML-page

Part 1: First steps

What is JavaScript
JavaScript is a new scripting language which is being developed by Netscape. With JavaScript you can easily create interactive web-pages. This tutorial shows you what can be done with JavaScript – and more importantly howit is done.
JavaScript is not Java!
Many people believe that JavaScript is the same as Java because of the similar names. This is nottrue though. I think it would go too far at the moment to show you all the differences – so just memorize that JavaScript is notJava.

Running JavaScript
What is needed in order to run scripts written in JavaScript? You need a JavaScript-enabled browser – for example the Netscape Navigator (since version 2.0) or the Microsoft Internet Explorer (MSIE – since version 3.0). Since these two browsers are widely spread many people are able to run scripts written in JavaScript. This is certainly an important point for choosing JavaScript to enhance your web-pages.
Of course you need a basic understanding of HTML before reading this tutorial. You can find many good online ressources covering HTML. Best you make an online search for ’html’ at Yahoo in order to get more information on HTML.

Embedding JavaScript into a HTML-page
JavaScript code is embedded directly into the HTML-page. In order to see how this works we are going to look at an
easy example:
<html>
<body>
<br>
This is a normal HTML document.
<br>
<script language= »JavaScript »>
document.write(« This is JavaScript! »)
</script>
<br>
Back in HTML again.
</body>
</html>
At the first glance this looks like a normal HTML-file. The only new thing is the part:
<script language= »JavaScript »>
document.write(« This is JavaScript! »)
</script>

Non-JavaScript browsers
What does our page look like if the browser does not understand JavaScript? A non-JavaScript browser does not know the <script>tag. It ignores the tag and outputs all following code as if it was normal text. This means the user will see the JavaScript-code of our program inside the HTML-document. This was certainly not our intention. There is a way for hiding the source code from older browsers. We will use the HTML-comments <!– –>. Our new source code looks like this:
<html>
<body>
<br>
This is a normal HTML document.
<br>
<script language= »JavaScript »>
<!– hide from old browsers
document.write(« This is JavaScript! »)
// –>
</script>
<br>
Back in HTML again.
</body>
</html>

…..

Si le lien ne fonctionne pas correctement, veuillez nous contacter (mentionner le lien dans votre message)
Cours Javascript (529 KO) (Cours PDF)
Introduction to javascript

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *