JavaScript Tutorials
Tutorials
JavaScriptJavaScript Location Object
JavaScript Window Object Methods
JavaScript Window Object Methods
In the section detailing the Introduction to JavaScript and DOM objects, this tutorial presented the list of methods used with Window object. These methods of Window objects are repeated below for referral. The syntax and usage of the methods of Window Objects with explanation in detail about each will be described in the next few sections of this tutorial.
The methods of Window Objects are:
- alert()
- blur()
- setInterval()
- clearInterval()
- setTimeout()
- clearTimeout()
- close()
- confirm()
- createPopup()
- focus()
- moveBy()
- moveTo()
- open()
- print()
- prompt()
- resizeBy()
- resizeTo()
- scrollBy()
- scrollTo()
alert():
By using the alert() method of window object, users can display an alert box with a message displayed in it as specified by the user.
The string passed to the alert method in argument displays an alert dialog box along with an Ok button inside it. NOTE: The alert() method is used to convey a message where the decision from the user is not required.
General Syntax of the alert() method of window object:
|
An example to understand the usage of alert() method of window object in brief:
|
The output of the above example is a button with the message:
|
When this button is clicked, the alert box is displayed with the message:
|
and an ok button displays in the alert box.
The string passed to the alert() method mentioned in the function exforsys() is Welcome!!! This is displayed in the alert box with the ok button.
If a user wants to display messages in alert box by having a line break in the next line then, this is achieved by placing a '\n' between messages and concatenating the messages using the symbol +.
An example to understand the above concept:
|
The output of the above example is a button with the message:
|
When this button is clicked, the alert box is displayed with the message:
|
And an ok button is displayed in this alert box.
In the above example, the message Have a Good Day!!! is placed after '\n' and thus is displayed in the next line of the previous Welcome message.
blur():
The blur() method of a Window object removes the focus from the current window. The blur() method of a window object is used to take the focus away from the current window.
General Syntax of the blur() method of window object:
|
An example to understand the usage of blur() method of window object:
|
In the above example, the focus is taken away from the current window (the exforsys window). The window named exforsys is opened using the window.open. The focus from the current window (exforsys) is removed using the exforsys.blur() statement.
setInterval():
The setInterval() method of a window object takes two arguments. The first argument is a function or an expression and the second argument is milliseconds. The setInterval() method of a window object is used to call a function or evaluate an expression at specified intervals (in this example, milliseconds). The calling of function or expression is continued until the window is closed or until the clearInterval() method is called. The setInterval() method returns an ID value which is used as a parameter for clearInterval method.
General Syntax of the setInterval() method of window object:
|
The expression/function mentioned is evaluated at specified intervals (milliseconds).
clearInterval():
The setInterval() method of a window object is used to call a function or evaluate an expression at specified intervals. The interval set by the setInterval() method of a window object cancels with the clearInterval() method of a window object.
General Syntax of the clearInterval() method of window object:
|
Here, the intervalID mentioned in argument of clearInterval() method represents the ID value returned by the setInterval() method.
First Page: JavaScript Location Object
