We
have just lauched a new forum where you can ask anything
about all these topics: Windows, Excel, Word, Internet and more.
Introduction to JavaScript
Added: 2005-01-20, Views: 4271, Ratings: 0
'JavaScript' is a scripting language available in many of the Internet browsers, interacting with HTML code. It was initially developed by Netscape and is based on C++ / Java. This is not the only scripting language available in browsers - you might use VBScript especially in Internet Explorer.
There are a few versions of this language script, but many times we only need JavaScript 1.0. JavaScript has a few objects like window or document, which have a few methods and properties. This is just an introduction, so we don't list all these methods and objects.
JavaScript (or JS) is introduced by a HTML tag: <script></script>. You can mention its version or to use JS code fron an external file:
<script language="JavaScript" src="some_file.js"></script>
This will use JS code from some_file.js from current folder. Another solution is to write JS code directly in this file between <script> & </script> tags (see below).
There are many situations when you need JavaScript to interact with the user from the browser, like displaying a message box, a confirmation, openning an additional window (popup) or validating some values from a form. All these can't be performed without JS. This scripts could be wherever in your page, both in <head> .. </head> or <body> .. </body>. If you write the code in BODY it's important to have scripts defined before you use them.
The simplest way is to show you some examples.
First one is to show a message when page opens (place this code somewhere in BODY):
<script language="JavaScript">alert("Welcome to my page!");</script>
Second example is to open a new window when click a link:
<a href="javascript:void(0)" onclick="javascript:window.open('http://google.com');">Click here</a> to open a new page.
More examples will be shown in other articles where we should explain more details about JavaScripts. Many sites are using intensively JavaScript to display their content, just that many of these examples are not trivial. We hope we started your interest in studying more JavaScript.
Comments: