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 / 31
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

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

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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