Online Software Educational Training - IT Tutorials - Online Education Training for Computer Software


Home

JAVA SCRIPT

Messing with status bar

 

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.

<Previous                                                                                                      Next>