简体   繁体   English

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

[英]Reloading parent window with a button in the iframe

I have an iframe in a page like 我在页面中有一个iframe

<iframe src="something.html"></iframe>

and in the something.html page, I have a form and a button. something.html页面中,我有一个表单和一个按钮。

<form action="anywhere.html">
<input type="button" name="submit" value="submit">
</form>

When I click on the submit button, it only reloads the page anywhere.html (inside the iframe). 当我点击提交按钮时,它只会重新加载任何地方的页面(在iframe内)。 But I want anywhere.html to load in the same main window (not in a new tab or window or not in the iframe). 但我希望anywhere.html加载到同一个主窗口(不是在新的选项卡或窗口中,也不在iframe中)。 How can this be done? 如何才能做到这一点?

Use the target attribute for the form tag. 使用表单标记的target属性。 Set it to _parent to have the form submit to the parent window (outside the frame). 将其设置为_parent以将表单提交到父窗口(框架外)。

  • _parent : Load the response into the HTML 4 frameset parent of the current frame, or HTML5 parent browsing context of the current one. _parent :将响应加载到当前帧的HTML 4 frameset parent或当前帧的HTML5 parent浏览上下文中。 If there is no parent, this option behaves the same way as _self . 如果没有父项,则此选项的行为与_self相同。 1 1
<form action="anywhere.html" target="_parent">
<input type="button" name="submit" value="submit">
</form>

See it demonstrated in this plunker . 看到它在这个plunker中演示。


1 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target 1 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-target

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM