JavaScript – Basic Structure
What is JavaScript?
JavaScript (JS) is an interpreted computer programming language. As part of web browsers, implementations allow client-side scripts to interact with the user.
JavaScript was born in 1995, and it was developed by Netscape Communications Corporation.
See Wikipedia for further information at: http://en.wikipedia.org/wiki/JavaScript
A basic JavaScript Example:
<!DOCTYPE html> <html> <head> <title>Title</title> <style type="text/css"> ... CSS code ... </style> <script type="text/javascript" src="esempio.js"></script> <script language="javascript"> /* This is a comment in 2 or more lines */ // This is a siongle line comment // ... JavaScript code ... document.write("JavaScript Rules! YEAH!"); </script> <noscript> Your browser does not support JavaScript! <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> </noscript> </head> <body> ... this is the web page content ... </body> </html>
How to load an external file
<script type="text/javascript" src="esempio.js"></script>
How to write code inside html5 page
<script language="javascript"> /* This is a comment in 2 or more lines */ // This is a siongle line comment // ... JavaScript code ... document.write("JavaScript Rules! YEAH!"); </script>
If JavaScript is not enable:
<noscript> Your browser does not support JavaScript! </noscript>
How to redirect if JavaScript is not enabled:
<noscript> Your browser does not support JavaScript! <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> </noscript>