Jump to content

close window button


knowram

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?
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.