Window Object Example
<html>
<head>
<title>Window Object</title>
<script language="JavaScript">
opened=0
window.defaultStatus="Program using window object"
function func1()
{
var1=open("event1.html", "win1", "menubar=no, toolbar=no")
opened=1
window.status="event1.html is now opened"
}
function func2()
{
if (var1.closed)
{
alert("Window already closed")
window.status="event1.html is closed"
}
else
{
var1.close()
window.status="event1.html is closed"
opened=0
}
}
function func3()
{
if (!var1.closed)
{
alert("Child Window Open - cannot close")
}
else
{
if (confirm("Close window?"))
{
window.close()
}
}
}
function func4()
{
if ((!var1.closed) && (opened==1))
{
var1.document.bgColor="#FF0000"
var1.focus()
}
else
{
alert("event1.html Window Not Open")
}
}
function func5()
{
if ((!var1.closed) && (opened==1))
{
var1.document.bgColor="#0000FF"
var1.focus()
}
else
{
alert("event1.html Window Not Open")
}
}
function func6()
{
if ((!var1.closed) && (opened==1))
{
var1.document.bgColor="#00ff00"
var1.focus()
}
else
{
alert("event1.html Window Not Open")
}
}
</script>
</head>
<body>
<center>
<br><br>
<input type="button" name="but1" value="Open event1.html"
onClick='func1()'>
<br><br>
<input type="button" name="but2" value="Close event1.html"
onClick='func2()'>
<br><br>
<input type="button" name="but3" value="Close this window"
onClick='func3()'>
<br><br>
<hr align="center" width="50%">
<p align="center">click the buttons below to change background
color of new window</p>
<input type="button" name="but4" value="red" onClick='func4()'>
<input type="button" name="but5" value="blue" onClick='func5()'>
<input type="button" name="but6" value="green" onClick='func6()'>
</center>
</body>
</html>
0 comments:
Post a Comment