Sample Code for window.close()
<html>
<head>
<title>JavaScript Window Close Example </title>
</head>
<SCRIPT language="JavaScript1.2">function closepopup()
function popuponclick()
{
my_window = window.open("",
"mywindow","status=1,width=350,height=150");
my_window.document.write('<H1>The Popup Window</H1>');
}
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert(‘Window already closed!’);
}
}
</SCRIPT>
<body>
<P>
<A href="javascript: popuponclick()">Open Popup Window</A>
</P>
<P>
<A href="javascript: closepopup()">Close the Popup Window</A>
</P>
</body>
</html>
use something like this for waiting # sec before loading url link.
<BODY>
<script type=text/javascript>
function goNow() {
document.location=_l;
}
function setUp() {
setTimeout(“goNow()”,_time); // 3 seconds delay
}
var _l = “http://www.urlhere.com/”;
var _time = 3000; // msecs.
onLoad=’setUp()’;
</script>
</BODY>
referring info at this page:
http://www.js-examples.com/example/?ex=272
The action page (after processing the form) should generate html like this:
<html>
<head>
<script type=”text/javascript“>
if (window.opener && !window.opener.closed) window.opener.location.href=”successpage.htm”;
window.close();
</script>
</head>
<body>
</body>
</html>
But I prefer to display the success page in the popup itself:
<html>
<head>
</head>
<body onload=”setTimeout(‘window.close()’, 3000)”>
The page has been successfully processed.
<form>
<input type=”button” value=”Close” onclick=”window.close()”>
</form>
</body>
</html>
If you want to do something in the main window (like reload it or navigate to another url)
<html>
<head>
<script type=”text/javascript“>
function doClose(){
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
//or
//window.opener.location.href=”somepage.htm”;
}
window.close();
}
</script>
</head>
<body onload=”setTimeout(‘doClose()’, 3000)”>
The page has been successfully processed.
<form>
<input type=”button” value=”Close” onclick=”doClose()”>
</form>
</body>
</html>
I used the following code on the success page, works like a charm. It even recognized that the referring window was the iframe from the parent page and loaded the successdefault.html into the iframe as it should Thanks again!
<head>
<script type=”text/javascript“>
function doClose(){
if (window.opener && !window.opener.closed) {
//window.opener.location.reload();
//or
window.opener.location.href=”successdefault.html”;
}
window.close();
}
</script>
</head>
<body onLoad=doClose()>
The action page (after processing the form) should generate html like this:
<html>
<head>
<script type=”text/javascript“>
if (window.opener && !window.opener.closed) window.opener.location.href=”successpage.htm”;
window.close();
</script>
</head>
<body>
</body>
</html>
But I prefer to display the success page in the popup itself:
<html>
<head>
</head>
<body onload=”setTimeout(‘window.close()’, 3000)”>
The page has been successfully processed.
<form>
<input type=”button” value=”Close” onclick=”window.close()”>
</form>
</body>
</html>
If you want to do something in the main window (like reload it or navigate to another url)
<html>
<head>
<script type=”text/javascript“>
function doClose(){
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
function DoSomething()
{
var outW = window.open(“”, “newwin”, “top=250, left=250, height=150, width=300″);
outW.document.write(“<HTML>”)
outW.document.write(“<TITLE>Confirmation</TITLE>”);
outW.document.write(“<body onload=’setTimeout(‘window.close()”, 5000>”);
outW.document.write(“<font color=#0000CC>”);
outW.document.write(“<div align=center><strong>Thank You”);
outW.document.write(“<P>Your Information has been received.</P></strong></div></font>”);
outW.document.write(“</body></HTML>”);
window.close();
//outW= window.setTimeout(document.close(), 2000);
}
//or
//window.opener.location.href=”somepage.htm”;
}
window.close();
}
</script>
</head>
<body onload=”setTimeout(‘doClose()’, 3000)”>
The page has been successfully processed.
<form>
<input type=”button” value=”Close” onclick=”doClose()”>
</form>
</body>
</html>
You have nested quotes and invalid <body> tag.
function DoSomething()
{
var outW = window.open(“”, “newwin”, “top=250, left=250, height=150, width=300″);
outW.document.write(“<HTML>”)
outW.document.write(“<TITLE>Confirmation</TITLE>”);
outW.document.write(“<body onload=\”setTimeout(‘window.close()’, 5000)\”>”;
outW.document.write(“<font color=#0000CC>”);
outW.document.write(“<div align=center><strong>Thank You”);
outW.document.write(“<P>Your Information has been received.</P></strong></div></font>”);
outW.document.write(“</body></HTML>”);
outW.document.close();
window.close();
}