View Full Version : Close Window not working

07-16-2009, 06:45 PM
I have a basic insert form to add items to a product database. It opens as a pop-up window from a different form so that my sales reps can add items to the database if they are not there without having to back track. I want to have a close window option for when they are done.

here is what I have so far:

<div id="wrapper">
<div id="titlebar"><img src="images/header.jpg" alt="Graphic Edge Printing" /></div>
<div id="maincontent">
<div id="nav">
<?php include('navbar.php'); ?>
<h1 align="center">Sheet Size Insert </h1>
<p align="center">Check the list below, if the sheet size you would like to use is not listed, please add it. </p>
<form action="<?php echo $editFormAction; ?>" id="Press" name="Press" method="POST">
<table width="457" border="0" cellspacing="0" cellpadding="2" align="center">
<td width="128"><div align="right">Sheet Size : </div></td>
<td width="189"><input type="text" name="SheetDesc" /></td>
<td width="128"><center><input name="Add Size" type="submit" id="Add Size" value="Add Size" />

<input type="hidden" name="MM_insert" value="Press">
<p align="center">&nbsp;</p>
<table width="200" border="1" cellspacing="0" cellpadding="2" align="center">
<th scope="col">Sheet Size Options </th>
<?php do { ?>
<td><div align="center"><?php echo $row_SheetSize['SheetDesc']; ?></div></td>
<?php } while ($row_SheetSize = mysql_fetch_assoc($SheetSize)); ?>
<input name="button" type="button" onclick="window.close()" value="Close Window" />
<div id="footer"><?php include('copyright.php'); ?></div>

but the close window button doesn't work. any ideas?

07-16-2009, 06:56 PM
The browser can forbid the scripts to close windows. If you are using FF, check whether the option dom.allow_scripts_to_close_windows is set to true.

07-16-2009, 06:58 PM
Safari ATM actually.
I can check that, what if it fails though? Do have any other options?

07-16-2009, 07:13 PM
Will you please post a link to your page where I can test it myself?

07-16-2009, 07:17 PM

I removed the database access for security reasons.

07-16-2009, 07:18 PM
well flip!
now it works! but after I submit a record, it doesn't.
is there any reason running the insert record function then reloading the page would make the close window button not work?

07-16-2009, 07:35 PM
Most probably, when you are reloading the entire page, the popup window loses its association with an opener window and becomes an individual window, which does not treat the close() method.

07-16-2009, 07:41 PM
That makes sense.
is there a way around that?

07-16-2009, 08:29 PM
... maybe if you'll create the popup window with an iframe inside it, and you'll load the page with the form (http://graphicedgeprinting.com/test.php) into the iframe, while the 'close' button will be outside the iframe?

In the popup window (say, popup.htm)

<p><iframe id="ifrm" src="http://graphicedgeprinting.com/test.php" width="750" height="450"></iframe></p>

<!-- the button is outside the iframe -->
<p><input name="button" type="button" onclick="window.close()" value="Close Window" /></p>

In the opener window

<p><input name="button" type="button" onclick="window.open('popup.htm', '', '');" value="Open Window" /></p>

If the document is reloaded inside the iframe, it does not affect the popup window itself, so, the popup window can be closed with the "Close Window" button. Such a workaround... If it doesn't suit you, sorry, I do not see any other way.

07-16-2009, 09:28 PM
You are right, it is not ideal, but it will work for now until I can figure out a better way to do this.

Thank you!