Home arrow JavaScript arrow Page 2 - Some Simple JavaScript Functions
JAVASCRIPT

Some Simple JavaScript Functions


JavaScript can be one of the most useful additions to any web page. In this article, Annette shows us five quick 'n' easy ways that we can use JavaScript to add a touch of functionality to our web pages.

Author Info:
By: Annette Tennison
Rating: 4 stars4 stars4 stars4 stars4 stars / 30
January 31, 2002
TABLE OF CONTENTS:
  1. · Some Simple JavaScript Functions
  2. · JavaScript functions
  3. · JavaScript functions (contd.)
  4. · Conclusion

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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:

The output 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:

The status text in my browser window
blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials