background
|
|
Random

Linux
Linux Support
A small area on the internet for Linux Support.
More icon
|
|
Up Image
Navigation
Search this Site
Enter your search terms

Site Breadcrumb - You are here
|
Thau's JavaScript Tutorial
Lesson 3

by Thau!

Page 7 — Messing with the Status Bar

Move your mouse over the following two links and keep your eye on the bottom of the page.

Who do we love?
Why do we love them?

Here's the source code for the first link:

<a href="#" onMouseOver="window.status='Monkeys!';return true;">Who do we love?</a>
This says, "When the mouse is moved over this link, change the status bar." If you look closely, you'll notice a return true inside the onMouseOver. If you don't put that there, the browser will do what it normally does when you move your cursor over a link: It'll look at the URL in the href and put it in the status bar, replacing the text you cleverly put there. But by putting return true in the onMouseOver, you stop the browser from doing this. It's sort of like the return false you put inside onClicks to stop the browser from trying to load a Web page:
<a href="#" onClick="return false;">this link does nothing and goes nowhere!</a>

Why it's return false in an onClick but return true in an onMouseOver is one of those mysteries of life that are better left mysteries.

Objects Have Methods

In addition to properties, objects also have methods. Methods are the actions an object knows how to take. For example, Windows know how to open other Windows: window.open("URL,""name,""features"). This tells JavaScript to use the open method of the Window object to open a new window.

So, as in the example above, a method of an object is called the same way that a property is accessed: the object name, a period, and then the method. The main difference is that methods are always followed by parentheses that contain the parameters of the method. Even if the method takes no parameters, you still need the parentheses. For example, remember this?

var italic_hippy = hippy_monkey.italics();

Yup, strings are actually objects, and italics() is a method of the String object.

You've seen several other examples of Window methods and haven't known it. The dialog box calls alert and prompt are actually methods of the Window object. If you call:

window.alert("Viva la primate!");
You'll get an alert box that reads "Viva la primate!" The reason that we were able to just say alert("Viva la primate!"), as in earlier examples, is because window, being the default top-level object, can be left out. This means that open("URL","name,""features") does the same thing as window.open("URL,""name,""features").

I'm not going to go into all the methods of Window objects here, just two more: focus and blur. The focus method moves a window that's behind other windows to the front. The blur method does the reverse — it moves a window behind other windows. Unfortunately, blur and focus don't work with Internet Explorer 3.0 or Netscape 2.0, so again, if you're using either of these, it might be time to upgrade.

Try blurring this window.

The code inside the onClick for this link is:

onClick="window.blur();return false;"

The window.blur() tells the browser to send the window to the back. This is very nice, but it seems sort of silly to just blur the window that you're looking at. In order to use focus and blur more usefully, you need to know how to invoke method calls on other windows.

next page»