Search Articles:

 

Home Page

Top Articles

Advertising
Advice
Affiliate Programs
Awards
Business
CGI
Computers
Copywriting
CSS
DHTML
Direct Mail
Domain Names
EBooks
ECommerce
Education
Email
Environment
Family
Finance
Free
Government
Health
Hobbies
Home Business
Home Repair
HTML
Humor
Internet
Javascript
Law



Netcraze Network
Funny Links
Recados Para Orkut
Funny Videos
Street Racing Videos
Crash Videos
Cooking Videos
Sexy Videos
Animal Videos
Surfing Videos
Music News
Funny TV Clips
Fight Videos
Anime Videos
Baseball Videos
Basketball Videos
Football Videos
Golf Videos
Very Funny Pictures
Arcade Games
Myspace Codes
Hockey Videos
Wrestling Videos
Gamer News
Hot Celebs
Fishing Videos
Toys and Gadgets
Movie Trailers
Video Game Trailers
Fitness Videos
Cat Videos
Funny Commercials
Dog Videos
Cheerleading Videos
Poker
Offroad Videos
Hot Links

 Free Facebook Games 
Click Here to add to your profile

 

none

Some Useful JavaScript Tricks


Published by Mitchell Harper
Submitted: 13 February,2002

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: ,
like this:



These script tags can be placed anywhere on the page, however
it's common practice to place them between the and
tags. A basic HTML page that contains some JavaScript looks
like this:



My Test Page < itle><br><script language="JavaScript"><br><br> function testfunc()<br> {<br> var x = 1;<br> }<br><br></script><br></head><br><body><br> <h1>Hello</h1><br></body><br></html><br><br>For the examples in this article, you should use the basic<br>document format I have just shown you, inserting the JavaScript<br>code between the <script> and </script> tags. When you load the<br>page in your browser, the JavaScript code will be executed<br>automatically.<br><br>-----------------------------------------------<br>Displaying the browsers name and version number<br>-----------------------------------------------<br><br>The "navigator" object in JavaScript contains the details of the<br>users browser, including its name and version number. We can<br>display them in our browser using the document.write function:<br><br> document.write("Your browser is: " + navigator.appName);<br> document.write("<br>Its version is: " + navigator.appVersion);<br><br>I run Windows 2000 and Internet Explorer version 6, so the output<br>from the code above looks like this in my browser window:<br><br> Your browser is: Microsoft Internet Explorer<br> Its version is: 4.0 (compatible; MSIE 6.0b; Windows NT 5.0)<br><br>-----------------------------------------------<br>Changing the text in the status bar of the browser<br>-----------------------------------------------<br><br>To change the text in the status bar of a browser window, we just<br>change the "status" member of the "window" object, which<br>represents our entire browser window:<br><br> window.status = "This is some text";<br><br>-----------------------------------------------<br>Using an input box to get text from the user<br>-----------------------------------------------<br><br>Just like in traditional windows applications, we can use an<br>input box to get some text input from the user. The "prompt"<br>function is all we need:<br><br> var name = prompt("What is your name?");<br> document.write("Hello " + name);<br><br>The prompt function accepts just one argument (the title of the<br>input box), and returns the value entered into the text box. In<br>the example above, we get the users name and store it in the<br>"name" variable. We then use the "document.write" function to<br>output their name into the browser window.<br><br>-----------------------------------------------<br>Using a message box to display text to the user<br>-----------------------------------------------<br><br>We can display a message box containing an OK button. These<br>are great when you want to let the user know what is happening<br>during their time on a particular page. We can use a message box<br>to display the "name" variable from our previous example:<br><br> var name = prompt("What is your name?");<br> alert("Your name is: " + name);<br><br>The "alert" function takes one argument, which is the text to<br>display inside of the message box.<br><br>-----------------------------------------------<br>Changing the title of the browser window<br>-----------------------------------------------<br><br>To change the title of our web browser's window, we simply modify<br>the "document.title" variable, like this:<br><br> document.title = "My new title";<br><br>One bad thing about the "document.title" variable is that we can<br>only manipulate it in Microsoft Internet Explorer. Netscape's<br>implementation of JavaScript doesn't allow us to modify it.<br><br>-----------------------------------------------<br>In Closing<br>-----------------------------------------------<br><br>As you can see from the examples in this article, JavaScript is a<br>powerful scripting language that we can use to enhance our<br>visitors experience with our site. You shouldn't use JavaScript<br>too much, however, because in some cases it can annoy your<br>visitors and send them packing before your site even loads!<br><p><h1>About the Author</h1><p>Mitchell Harper is the founder of http://www.devarticles.com.<br>DevArticles provides its visitors with useful, informative<br>articles on ASP, PHP, and .NET, as well as heaps of tips and<br>tricks that you wont find anywhere else! To see what it's all<br>about, visit devArticles right now at http://www.devarticles.com</td> </tr> </table> </td> </tr> </table> </body> </html> </TD> </TR> </TABLE> </CENTER> </DIV> </TD> </TR> </TABLE> </TD> </TR> <TR> <TD WIDTH="100%" BGCOLOR="#FFFFFF" ALIGN="center" VALIGN="top" HEIGHT="77" BACKGROUND="/images/index_04.gif"> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" STYLE="border-collapse: collapse; font-family:Verdana; font-size:11px; color:#000000" BORDERCOLOR="#111111" WIDTH="100%" ID="AutoNumber11" HEIGHT="42"> <TR STYLE="font-family: Verdana; font-size: 11px; color: #000000"> <TD WIDTH="100%" VALIGN="top" HEIGHT="19" STYLE="font-family: Verdana; font-size: 11px; color: #000000"> <IMG SRC="/images/index_02.gif" WIDTH=806 HEIGHT=5 ALT=""></TD> </TR> <TR STYLE="font-family: Verdana; font-size: 11px; color: #000000"> <TD WIDTH="100%" VALIGN="bottom" HEIGHT="23" STYLE="font-family: Verdana; font-size: 11px; color: #000000"> <P ALIGN="center"><span class="SideHeading"><span class=small> Copyright © 2002-2006 - FreeArticleSearch.com - <script language="Javascript" src="http://WhoIsOnline.net/?action=track&siteurl=http://freearticlesearch.com"></script> </SPAN></SPAN></TD> </TR> </TABLE> </TD> </TR> </TABLE> <a href="ror.xml"><img src="http://www.rorweb.com/rorinfo.gif" width="80" height="15" border="0" alt="ROR"/></a> </CENTER> </DIV> </BODY> </HTML>