Exforsys

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction

Ads


Home arrow Technical Training arrow JavaScript Tutorial

JavaScript Window Object Methods

Page 2 of 2
Author : Exforsys Inc.     Published on: 4th Jul 2007

JavaScript Location Object

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.

Ads

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.

Ads

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.



 
This tutorial is part of a JavaScript Tutorial tutorial series. Read it from the beginning and learn yourself.

JavaScript Tutorial

  1. JavaScript Browser Objects Part 2
  2. JavaScript Frame object
  3. JavaScript Form Object
  4. JavaScript FileUpload Object
  5. JavaScript Event Object Properties and Methods
  6. JavaScript Event Object
  7. JavaScript Elements and Embed Objects
  8. JavaScript Applet Objects
  9. JavaScript Browser Objects
  10. JavaScript Object Oriented Features
  11. JavaScript Window Object Open Method Part 2
  12. JavaScript Window Object Open Method
  13. JavaScript Window Object Timeout Methods
  14. JavaScript Location Object
  15. JavaScript Location Object Properties
  16. JavaScript History Object Properties and Methods
  17. JavaScript Document Object Methods Part II
  18. JavaScript Document Object Methods Part I
  19. JavaScript Document Object Properties
  20. JavaScript Document Object
  21. JavaScript Windows Object Properties Part II
  22. JavaScript Windows Object Properties Part I
  23. JavaScript DOM Window Object
  24. Working with JavaScript DOM Objects
  25. JavaScript Array Object Methods – Part II
  26. JavaScript Array Object
  27. JavaScript Array Object Methods – Part I
  28. JavaScript Boolean Object
  29. JavaScript OnError Event
  30. JavaScript Exception Handling – Part II
  31. JavaScript Exception Handling – Part I
  32. JavaScript Event Handler
  33. JavaScript Events Handling
  34. JavaScript Array Operations
  35. JavaScript Two Dimensional Arrays
  36. Passing values to JavaScript Function
  37. JavaScript Functions
  38. JavaScript Arrays
  39. JavaScript Iterative Structures - Part II
  40. JavaScript Iterative Structures - Part I
  41. JavaScript Math Object
  42. JavaScript Date Object
  43. JavaScript String Object
  44. JavaScript Objects
  45. JavaScript Confirm Box
  46. JavaScript Alert Box
  47. JavaScript Conditional Statements Part 2
  48. JavaScript Conditional Statements Part 1
  49. How to use JavaScript in HTML page
  50. JavaScript Variables
  51. JavaScript Features
  52. JavaScript Introduction
 

Comments