JavaScript can be one of
most useful additions to any web page. It comes bundled with Microsoft Internet Explorer and Netscape Navigator and it allows us to perform field validations, mouse-overs images, open popup windows, and a slew of other things.In this article I will show you how to:
- Display
browser name and version number - Change
text in
status bar of
browser - Use an input box to get text from
user - Use a message box to display text to
user - Change
title of
browser window
Before that, however, we need to know how to setup our web page so that it can run
JavaScript. JavaScript code is inserted between opening and closing script tags: , like this:
These script tags can be placed anywhere on
page, however it's common practice to place them between
and tags. A basic HTML page that contains some JavaScript looks like this:
My Test Page < itle> Hello
For
examples in this article, you should use
basic document format I have just shown you, inserting
JavaScript code between
tags. When you load
page in your browser,
JavaScript code will be executed automatically.
----------------------------------------------- Displaying
browsers name and version number -----------------------------------------------
The "navigator" object in JavaScript contains
details of
users browser, including its name and version number. We can display them in our browser using
document.write function:
document.write("Your browser is: " + navigator.appName); document.write(" Its version is: " + navigator.appVersion);
I run Windows 2000 and Internet Explorer version 6, so
output from
code above looks like this in my browser window:
Your browser is: Microsoft Internet Explorer Its version is: 4.0 (compatible; MSIE 6.0b; Windows NT 5.0)
----------------------------------------------- Changing
text in
status bar of
browser -----------------------------------------------