使用 iframe 中的按钮重新加载父 window
Reloading parent window with a button in the iframe
我在这样的页面中有一个 iframe
<iframe src="something.html"></iframe>
在 something.html 页面中,我有一个表单和一个按钮。
<form action="anywhere.html">
<input type="button" name="submit" value="submit">
</form>
当我点击提交按钮时,它只会重新加载页面 anywhere.html(在 iframe 内)。但我希望 anywhere.html 在同一个主 window 中加载(不在新选项卡或 window 中或不在 iframe 中)。如何做到这一点?
使用 target attribute for the form 标签。将其设置为 _parent 以将表单提交给父级 window(在框架外)。
- _parent: Load the response into the HTML 4 frameset parent of the current frame, or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.1
<form action="anywhere.html" target="_parent">
<input type="button" name="submit" value="submit">
</form>
参见 this plunker 中的演示。
1https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target
我在这样的页面中有一个 iframe
<iframe src="something.html"></iframe>
在 something.html 页面中,我有一个表单和一个按钮。
<form action="anywhere.html">
<input type="button" name="submit" value="submit">
</form>
当我点击提交按钮时,它只会重新加载页面 anywhere.html(在 iframe 内)。但我希望 anywhere.html 在同一个主 window 中加载(不在新选项卡或 window 中或不在 iframe 中)。如何做到这一点?
使用 target attribute for the form 标签。将其设置为 _parent 以将表单提交给父级 window(在框架外)。
- _parent: Load the response into the HTML 4 frameset parent of the current frame, or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as _self.1
<form action="anywhere.html" target="_parent">
<input type="button" name="submit" value="submit">
</form>
参见 this plunker 中的演示。
1https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target