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

标签 javascript php html iframe form-submit

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

相关文章:

php - 如何在 Drupal 中获取当前页面的 URL?

javascript - JS - 如何从 HTML-span 中删除最后四个字符

javascript - CSS 'translate(0px, 0px)' 元素样式的正则表达式匹配值

javascript - 将应用程序部署到 Heroku,在后端 Java Spring Boot 中抛出 500 内部服务器错误,同时在本地环境中完美运行

javascript - 如何隐藏水平条并使左右按钮水平滚动?

php - 使用 php 循环更新 mysql 列

PHPOffice 写入新文件时出现 fatal error

javascript - 当您将 javascript 放在结束 body 标记之后会发生什么?

javascript - 将组件设置插入样式管理器

javascript - 使用 C# 修改 Javascript