1

This is related to question "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?

Community
  • 1
  • 1
qwertyuu
  • 1,055
  • 1
  • 10
  • 14

1 Answers1

1

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
  • 14,035
  • 12
  • 56
  • 81
  • 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 Sep 02 '09 at 01:15
  • 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 Sep 02 '09 at 06:07
  • 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 Sep 02 '09 at 12:44