Exforsys.com
 
Home Tutorials JavaScript
 

JavaScript Location Object

 

JavaScript Window Object Methods

Page 2 of 2


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:



alert(message)


An example to understand the usage of alert() method of window object in brief:



<html>
   <
head>
      <
script type="text/javascript">
         function exforsys()
         {
          alert("Welcome!!!")
         }
    </script>
</head>
<body>
   
<input type="button" onclick="exforsys()"
   
value="Example of alert() method of Window Object!!
    Click Here!!!
" />
   </body>
</
html>


The output of the above example is a button with the message:



Example of alert() method of Window Object!! Click Here!!!


When this button is clicked, the alert box is displayed with the message:



Welcome!!!!


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:



<html>
   <
head>
      <
script type="text/javascript">
         function exforsys()
         {
          alert("Welcome!!!" + '\n' +"Have a Good Day!!!")
         }
    </script>
</head>
<body>
   
<input type="button" onclick="exforsys()"
   
value="Example of alert() method of Window Object!!
    Click Here!!!
" />
   </body>
</
html>


The output of the above example is a button with the message:



Example of alert() method of Window Object!! Click Here!!!


When this button is clicked, the alert box is displayed with the message:



Welcome!!!
Have a Good Day!!!


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:



window.blur()


An example to understand the usage of blur() method of window object:



<html>
   <
body>
      <
script type="text/javascript">
         exforsys=window.open('','','width=100,height=100')
         exforsys.document.write("
Window is 'exforsys'")
         exforsys.blur()
     
</script>
 
</body>
</html>


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:



window.setInterval(expression/function, milliseconds)


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:



window.clearInterval(intervalID)


Here, the intervalID mentioned in argument of clearInterval() method represents the ID value returned by the setInterval() method.




First Page: JavaScript Location Object


Read Next: JavaScript Window Object Timeout Methods



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape