views:

183

answers:

1

This is related to question "http://stackoverflow.com/questions/1360618/bookmarklet-behind-elements".

I want to either self close the iframe after form submission or if not possible, add a close button with the iframe to close it. my bookmarklet at the moment is

javascript:(function(){var iFrame=document.createElement('IFRAME');iFrame.src='http://www.yeongbing.com/testform/dd-formmailer/dd-formmailer.php';iFrame.style.cssText='display:block;position:absolute;top:5%;left:60%;width:40%;height:51%;overflow:hidden;';document.body.insertBefore(iFrame,document.body.firstChild);})();

I have tried the methods mentioned here but can't seem to work. Any suggestions?

+1  A: 

Here's how you can close the iframe from your "Close Window" button.

First, give your iframe an id by adding "iFrame.id='foo';" to the end of your bookmarklet script:

javascript:(function(){var iFrame=document.createElement('IFRAME');iFrame.src='test2.html';iFrame.style.cssText='display:block;position:absolute;top:5%;left:60%;width:40%;height:51%;overflow:hidden;';document.body.insertBefore(iFrame,document.body.firstChild);iFrame.id='foo';})();

Then, in your iframe's source, change

<input type="button" onclick=window.close() value="Close Window"/>

to

<input type="button" onclick="parent.document.body.removeChild(parent.document.getElementById('foo'));" value="Close Window"/>
Emmett
Thanks for your input. But the button neither work on the page itself nor the iframe. Do you know why onclick=window.close() by itself doesn't work? I thought it should close the window no matter what is within the webpage.
qwertyuu
I tested my solution and it works. The button is in the iframe page itself, just as you already have on http://www.yeongbing.com/testform/dd-formmailer/dd-formmailer.php.
Emmett
very weird. I try it in Safari and firefox and it does not work in both of them. I will check to see if i copied it wrongly. Thanks
qwertyuu