1

这与问题“元素背后的书签”有关。

我想在提交表单后自行关闭 iframe,或者如果不可能,在 iframe 中添加一个关闭按钮来关闭它。我现在的书签是

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);})();

我已经尝试过这里提到的方法,但似乎无法正常工作。有什么建议么?

4

1 回答 1

1

以下是如何从“关闭窗口”按钮关闭 iframe。

首先,通过添加“iFrame.id='foo';”给你的 iframe 一个 id 到您的小书签脚本的末尾:

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';})();

然后,在您的 iframe 源中,更改

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

<input type="button" onclick="parent.document.body.removeChild(parent.document.getElementById('foo'));" value="Close Window"/>
于 2009-09-01T22:44:42.517 回答