gpt4 book ai didi

javascript - 使用 iframe 中的按钮重新加载父窗口

转载 作者:行者123 更新时间:2023-11-28 04:49:54 25 4
gpt4 key购买 nike

我在页面中有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com