Window Object
About Web Page:

In Every Web page, Window is an top level object. Our webpage is document object under window object. Any html table,button ,link etc all are object.Each Object has properties and method.

Let see window Object.

Properties
document,location,status etc.

Methods.
alert(),confirm(),focus(),open(),prompt(),setTimeout() etc.

window.open()

This method open new window. if you specify width and height then window looking like popup window().

<html>
<head>
<script type="text/javascript">
function new_window()
{
window.open('http://ittrainingonline.co.in','popup_window()','width=400,height=300,
scrollbars=yes');
}
</script>
</head>
<body>
<input type="button" value="Popup window" onclick="new_window()" />
</body>
</html>

window.print()

This method print the current page.

Example 2:-

<html>
<head>
<script type="text/javascript">
function currentpage()
  {
  window.print()
  }
</script>
</head>
<body>
<input type="button" value="Print" onclick="currentpage()" />
</body>
</html>

window.confirm()

This show popup window show ok and cancel button.
if user click on ok this method return true otherwise false.

Example 3:-

<html>
<head>
<script type="text/javascript">
function test()
  {
  window.confirm("This Message Window");
  }
</script>
</head>
<body>
<input type="button" value="Click Here" onclick="test()" />
</body>
</html>

window.prompt()

This method accept some input from user.

Example 4:-

<html>
<head>
<script type="text/javascript">
function show()
  {
  var fname=prompt("Enter your name:","Name")
  alert(fname);
  }
</script>
</head>
<body>
<input type="button" onclick="show()" value="Click Here" />
</body>
</html>

window.setTimeout()

<html>
<head>
<script type="text/javascript">
function show()
{
alert("This is test of settimeout function");
}
function callme()
{
setTimeout("show()",5000)
}
</script>
</head>
<body>
<form>
Click this buttion, but function call after 5 sec.<br>
<input type="button" value="Click Me" onclick="callme()" />
</form>
</body>
</html>


Previous
Next