Webmasters Heaven, Free submission, Free Promotion, Free Tools
Backword Forward Home add this page to favoirates send this page to a friend print this page icons articles Webmaster Tools Web Site Submit
sitemap
Free Icons Free Articels Free Tools Website submission

Articles Category  ]

Google
 
Advertising
Affiliates
Blogs
CGI
CSS
DHTML
Domain Names
ECommerce
Email
HTML
Internet
Javascript
Link Popularity
Marketing
MLM
Newsletters
Promotion
RSS
Search Engines
Site Security
Traffic Analysis
Web Hosting
Web Design
Webmasters


articles -> javascript
Article Title Author
A Recursive Filtering Workbench in Java Richard G. Baldwin
7 Reasons You Should Avoid JavaScript Dynamic Navigation Iain Row
Using External JavaScript Source Files Sasch Mayer
dhtmlxTabbar - Creating Dynamic Tabbed Interface Has Never Been Easier! Ivan Petrenko
dhtmlxTree version 1.3 - Add Flexibility to Your Web Trees Ivan Petrenko
Java tips & tutorials - best Subscriptions for learning Java Groshan Fabiola
Ajaxgear Toolkit Allan Spartacus Mangune
Evaluation of Keywords for an AdSense Oriented Website F. Terrence Markle
Submit form conditionally - JavaScript SiteArticles.com
New Customizable JavaScript Menu for Web Applications Ivan Petrenko
Capturing Video And Audio Streams How-To John Deprice
How to handle web surfers, who disabled JavaScript Michael Kashirin
Simplified form to mail: Unlimitted input Endar WS
Anti right-click pop up : pop up will appear if visitors right-clicks his mouse Endar WS
Password protected document : Protect your web page with specific password for each member Endar WS
Building HTML codes automatically, just copy&paste your content Endar WS
Javascript Password Protection Timur Abdrakhmanov
How to test for the Javascript DOM? Riaan Pieterse
Interactive Forms Brian Zimmer
Validating Numerical Input with JavaScript David Morse
Instant plug-in scripts that help you profit... "Special offer expiry date with a twist" Michel Komarov
Javascript Basics 01 Lisa Spurlin
Javascript; Browser Detection and Page Redirection William J. Tolson
Ask Mr. D - JavaScript Bill Daugherty
Grow Your Subscribers Exponentially With These Javascript E-mail Capture Boxes! Vishal Rao
Some Useful JavaScript Tricks Mitchell Harper
Validating Form Input in JavaScript Amrit Hallan
Using External JavaScript Files Amrit Hallan
Guide to creating simple chromeless popup windows Michael Bloch
Dirty Web Promotion Tricks #1 - Legitimate and Malicious Javascripts Michael Bloch
Spice Up Your Web Site with JavaScript Shelley Lowery
Make your website scream with excitement with Java! Johnathan Wyka-Warzecha

Some Useful JavaScript Tricks   by Mitchell Harper


JavaScript can be one of the 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 the browser name and version number - Change the text in the status bar of the browser - Use an input box to get text from the user - Use a message box to display text to the user - Change the title of the browser window

Before that, however, 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 < itle> <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("
Its version is: " + navigator.appVersion);

I run Windows 2000 and Internet Explorer version 6, so the output from the 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 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";

----------------------------------------------- Using an input box to get text from the user -----------------------------------------------

Just like in traditional windows applications, we can use an input box to get some text input from the user. The "prompt" function is all we need:

var name = prompt("What is your name?"); document.write("Hello " + name);

The prompt function accepts just one argument (the title of the input box), and returns the value entered into the text box. In the example above, we get the users name and store it in the "name" variable. We then use the "document.write" function to output their name into the browser window.

----------------------------------------------- Using a message box to display text to the user -----------------------------------------------

We can display a message box containing an OK button. These are great when you want to let the user know what is happening during their time on a particular page. We can use a message box to display the "name" variable from our previous example:

var name = prompt("What is your name?"); alert("Your name is: " + name);

The "alert" function takes one argument, which is the text to display inside of the message box.

----------------------------------------------- Changing the title of the browser window -----------------------------------------------

To change the title of our web browser's window, we simply modify the "document.title" variable, like this:

document.title = "My new title";

One bad thing about the "document.title" variable is that we can only manipulate it in Microsoft Internet Explorer. Netscape's implementation of JavaScript doesn't allow us to modify it.

----------------------------------------------- In Closing -----------------------------------------------

As you can see from the examples in this article, JavaScript is a powerful scripting language that we can use to enhance our visitors experience with our site. You shouldn't use JavaScript too much, however, because in some cases it can annoy your visitors and send them packing before your site even loads!

About the Author

Mitchell Harper is the founder of http://www.devarticles.com. DevArticles provides its visitors with useful, informative articles on ASP, PHP, and .NET, as well as heaps of tips and tricks that you wont find anywhere else! To see what it's all about, visit devArticles right now at http://www.devarticles.com


[Advertisement ]