我在页面中有一个 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 在同一个主窗口中加载(不是在新选项卡或窗口中,也不是在 iframe 中)。如何做到这一点?
最佳答案
使用target form 的属性标签。将其设置为 _parent 以使表单提交到父窗口(框架之外)。
- _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 中的演示.
<小时/>1 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target
关于javascript - 使用 iframe 中的按钮重新加载父窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43006597/