Some Simple JavaScript Functions - JavaScript functions
(Page 2 of 4 )
Before we can implement the functions i'm about to describe, we need to know how to setup our web page so that it can run the JavaScript. JavaScript code is inserted between opening and closing script tags: <script> and </script>, like this:
<script language="JavaScript">
// JavaScript code goes here
</script>These script tags can be placed anywhere on the page, however it's common practice to place them between the <head> and </head> tags. A basic HTML page that contains some JavaScript looks like this:
<html>
<head>
<title> My Test Page </title>
<script language="JavaScript">
function testfunc()
{
var x = 1;
}
</script>
</head>
<body>
<h1>Hello</h1>
</body>
</html>For the examples in this article, you should use the basic document format I have just shown you, inserting the JavaScript code between the <script> and </script> tags. When you load the page in your browser, the JavaScript code will be executed automatically.
Displaying the browsers name and version number The "navigator" object in JavaScript contains the details of the users browser, including its name and version number. We can display them in our browser using the document.write function:
document.write("Your browser is: " + navigator.appName);
document.write("<br>Its version is: " + navigator.appVersion);I run Windows 2000, Internet Explorer version 5.5 and HotBar, so the output from the code above looks like this in my browser window:
Changing the text in the status bar of the browser To change the text in the status bar of a browser window, we just change the "status" member of the "window" object, which represents our entire browser window:
window.status = "This is some text";Take a look at the status text of my browser window after I added the line of code above into my HTML page:

Next: JavaScript functions (contd.) >>
More JavaScript Articles
More By Annette Tennison