Window Object Part II



  • Abstract
  • Advanced Properties
  • Example #1
  • Advanced Methods
  • Example #2
  • Summary




    Abstract:

    In this second article on the window object, we will see advanced properties, methods and examples of "window" object. You must have some basic knowledge about objects, properties and methods to go any further.


    Advanced Properties:

    defaultStatus is one of the properties of the window object. It is used to set the default message to be displayed in the status bar. In most browsers the status bar is empty by default. However, you can set it to display some text by setting window.defaultString to the text. All your mouseOvers will return to this string when you remove your mouse from a link. Following is a trivial example that explains this idea:


    Example #1

    <html>
    <head>
    <title>window.defaultStatus</title>
    </head>

    <body>
    Enter the text for the status line. Then move your mouse over this <a href="http://www.yahoo.com" onMouseOver="window.status='Yahoo!'; return true">link</a> to see the code in action.<br>

    <form>
    <input type="text" size="60" name="inputBox">
    <input type="button" value="change" onClick="window.defaultStatus=inputBox.value;">
    </form>
    </body>
    </html>

    This code creates a link with a mouseOver, a text box and a button. When you type something in the textbox and click on the button, the status bar is set to display the text in the box. When you move your mouse on the link afterwards, the status bar temporarily changes to display the text associated with the link. It returns back to the text supplied by you when your mouse leaves the link. You can view the code in action at http://www.suite101.com/files/topics/6196/files/window2.html


    Advanced Methods

    First of all I will like to discuss User Interaction methods of the window object. You are probably familiar with the alert('some text to display) method. It actually belongs to the window object: you can either write window.alert() or simply alert().

    If you don't know the alert() method, don't despair. I will explain it to you. This method displays a message to the user (such as "Welcome to my homepage", etc.). There is only one button on the displayed message box: an OK button.

    The second important method is confirm('Are you sure?') method. As in the case of alert() method, you can write window.confirm() or simply confirm. The message box displayed as a result has two buttons: an OK and a Cancel button. This methods return a boolean value: that is either 1 (for true) or 0 (for false). You can use the returned value as an expression to be checked in an if statement.

    Third important method is prompt ('my message', 'default text'). The first string is a message that will be displayed alongwith an input text box. The second parameter 'default text' is displayed in the text box.

    The copyright of the article Window Object Part II in JavaScript is owned by Muhammad Ali Shah. Permission to republish Window Object Part II in print or online must be granted by the author in writing.

    Go To Page: 1 2

    Articles in this Topic    Discussions in this Topic