The Important Methods of Window Object Are As Follows
The Important Methods of Window Object Are As Follows
The Important Methods of Window Object Are As Follows
The window object represents a window in browser. An object of window is created automatically by the browser.
Window is the object of browser, it is not the object of javascript. The javascript objects are string, array, date etc.
confirm() displays the confirm dialog box containing message with ok and cancel button.
setTimeout() performs action after specified time like calling function, evaluating expressions etc.
1
2
4. alert("I am "+v);
5.
6. }
7. </script>
8. <input type="button" value="click" onclick="msg()"/>
The JavaScript history object represents an array of URLs visited by the user. By using this object, you can load previous, forward or
any particular page.
2
3
onfocus occurs when an element gets focus such as button, input, textarea etc.
onmouseout occurs when mouse is moved out from an element (after moved over).
onmouseup occurs when mouse is released from an element (after mouse is pressed).
3
4
Program 1
<html>
<head>
<script>
function url1(){
window.open("http://www.gmail.com");
}
function url2(){
window.location = 'http://www.gmail.com';
}
</script>
</head>
<body>
<input type="button" value="using open method" onclick="url1()"/> <br>
<input type="button" value="using open method without function" onclick="window.open('http://espn.com')"/> <br>
<input type="button" value="using window property" onclick="url2()"/>
<br><br><br>sdbsdgs<br><br><a onclick="window.close()"> close me </a>
</body>
</html>
Program 2
<html>
<head>
<script>
</script>
</head>
<body>
<input type="button" value="open method"
onclick="open('p1.html','','width=300,height=200,left=600,top=300,address=no,toolbar=no')">
</body>
</html>
Program 3
<html>
<head>
<script>
function x() {
alert('you entered age!');
}
</script>
</head>
4
5
<body>
<a onmouseover="document.getElementById('sp1').innerHTML='this is link 1'"> Link 1 </a>
<a onmouseover="document.getElementById('sp1').innerHTML='this is link 2'"> Link 2
</a>
<a onmouseover="document.getElementById('sp1').innerHTML='this is link 3'"> Link 3 </a>
<br><br><br>
<span style="width:600px;font-size:2em;border:1px solid green" id="sp1">the message will display here </span>
</body>
</html>
Program 4
<html>
<head>
<script>
function x() {
alert('you entered age!');
}
</script>
</head>
<body>
<a onmouseover="pic1.src='j2.jpg'" onmouseout="pic1.src='j1.jpg'"> Link 1 </a>
<a onmouseover="pic1.src='j3.jpg'"> Link 2
</a>
<a onmouseover="pic1.src='j4.jpg'"> Link 3 </a>
<br><br><br>
<span style="width:600px;font-size:2em;border:1px solid green" id="sp1"><center> <img id="pic1" src="j1.jpg"> </center></span>
</body>
</html>
Program 5
<html>
<head>
<script>
function x() {
var a=document.getElementById('txta');
alert('hello! you are '+a.value + ' years old!');
}
</script>
</head>
<body>
Enter your age <input type="text" id="txta" onkeyup="x()">
</body>
</html>