Home arrow Tutorials arrow onMouseover: Your first Script

Web Development

Welcome to Web Development section. Please choose a category. 
 
  • Hrvatski tutorijali
    Ovdje su objavljeni razni tutorijali na hrvatskom jeziku na temu PC, programiranje, web development, savjeti, trikovi, optreba racunala itd.
  • Tips / Tricks
    Articles about various tips and tricks concerning Windows, Linux and other OS usage.
  • JavaScripts
    Code snippets, tutorials and tricks for JavaScrip language.
  • PHP & MySQL
    Tutorials, code examples, tips and tricks for PHP and MySQL development.
  • Tutorials
    Place for tutorials about using various application in best and simplest way.
onMouseover: Your first Script PDF Print E-mail
(0 votes)

onMouseover: Your first Script
Make something happen by surprise. Well, it used to be a surprise, but it is used quite a bit now.

Well, its time to try out your first javascript. This one is nice because we don't have to deal with adding the script tag. This little script will write something of your choice to the browser's status bar when you move your mouse over a link. Let's look at the example:

<A href="jmouse.htm" onMouseover="window.status='Hi there!'; return true">Place your mouse here!</A>

I'll explain all this in a second. Go ahead and see what it does. Place your mouse pointer over the link, but don't click it. Now look down at the status bar at the bottom of your browser. It will say "Hi there!"

Place your mouse here!

Okay, here's what is happening with the onMouseover command:

 

  1. onMouseover=" "
    This is the form of the onMouseover command. The browser expects another command or function inside the quote marks.

     

  2. window.status='Hi there!'
    This command instructs the browser to write to the status bar. You place what you want the browser to write inside the single quote marks.

     

  3. return true
    Returns the statement as true so the browser will display the text.

The reason for the single quote marks is because in this case, the window.status command is used inside the onMouseover command, which was already using double quotes. If we had used another set of double quotes, the browser would have gotton confused about what it should do because it would think the onMouseover command had ended when we began the window.status command:   onMouseover=""window.....

Well, one thing that could be bugging you is the fact that the "Hi There!" is now in your status bar and won't leave. There are two ways to fix this problem. One way is to use the onMouseout command, and another is to call a function that will erase the text after a specified amount of time. The second way requires using functions and the script tags, so for now I will show you the easiest way to do it: the onMouseout command. Here it is:

<A href="jmouse.htm" onMouseover="window.status='Hi there!'; return true"
onMouseout="window.status=' '; return true">Place your mouse here!</A>

Keep all of the code above on one line, the line breaks above for the ease of reading the code. This will make the text disappear from the status bar when you move your mouse off of the link. Give it a try:

Place your mouse here!

We did the same thing as before, except inside the onMouseout command we used a space inside the window.status command rather than text. This script is pretty fun, and can be helpful for your visitors if you use your text to describe where a link will take them.

 
< Prev   Next >
What's your favorite Internet browser?
 

Login






Lost Password?

Tools

Coming soon...

Partners

Syndicate