Jump to content

Archived

This topic is now archived and is closed to further replies.

knowram

close window button

Recommended Posts

I have a page that reloads itself every time you hit a different submit button. I am trying to put a button on the bottom of the page that the user can use to close the window when they are done. Here is the code that I am using so fare

[code]
        <input type="button" value="Close Window" onClick="self.close();" >
[/code]

this works great the first time the page loads if that is the first thing you click. But if you use a different button which reloads the page the close window button will no longer work.

anyone know how to fix this problem?

Share this post


Link to post
Share on other sites
You only can close a window if it was open by a script. Once the page is reloaded (or the URL is changed) the page is not considered to be opened by a script anymore, so the self.close() won't work.

Share this post


Link to post
Share on other sites
is there anyway to use a link or button to close the window at that point?

Share this post


Link to post
Share on other sites
I don't think so, but I am not 100% sure.

Maybe if you tried to load the page content in an iframe and the button on the page itself.

Share this post


Link to post
Share on other sites
Great idea but I am passing information to the page through the link so I don't think i can use iframes. unless there is a way to pass information to an ifram with the link.

Share this post


Link to post
Share on other sites
you can trying something like this. Let's say you are passing ID as a variable to page.php?ID=3
[code]
<?PHP
$iframe_link = "iframe_page.php?ID=".$_GET['ID']
?>
<iframe src="<?= $iframe_link ?>"></iframe>
<button onclick="window.close();">Close</button>
[/code]
this should pass the ID variable to the iframe page.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.