在iframe中发布表单

编程入门 行业动态 更新时间:2024-10-27 03:34:51
本文介绍了在iframe中发布表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在iframe中发布一个表单,像这样生成:

我的JS在页面内加载一个iframe,向iframe添加一个表单并提交表格。我想要发生的是加载该请求结果的iframe。因此,我希望有效地发布表单并在iframe中呈现结果 ,而不触及父级(除了将iframe放在第一位显示外)。

我使用这个答案中的代码:

JavaScript post request like a form submit

但我无法让它不能重新加载父项。我发布表单,而不是iframe刷新,整个父级刷新。我不知道这是为什么,因为它发布的网址是不同的,至少会重定向到那里。

任何人都可以帮我解决这个问题吗?我只想在iframe中放置一个帖子,并且只在iframe中,基本上。编辑:经过一些更多的研究,显然表单没有被正确创建。我使用了document.createElement(form),然后是document.getElementById(my_iframe_id)。appendChild(form)来追加它,但它似乎没有正常工作。

解决方案

正确,因为您正在当前文档中创建表单节点。

的document.getElementById( my_iframe_id)contentWindow.document.createElement( '形式')。

在iframe中创建它。

I would like to POST a form in an iframe, generated like so:

My JS loads an iframe inside the page, adds a form to the iframe and submits the form. What I would like to happen is the iframe to load the result of that request. So, I would effectively like to post a form and render the result inside the iframe, without touching the parent (apart from putting the iframe up for display in the first place).

I am using the code from this answer:

JavaScript post request like a form submit

but I can't get it to not reload the parent. I post the form, and instead of the iframe refreshing, the entire parent refreshes. I don't know why that is, since the url it's posting to is different and would at least redirect there.

Can anyone help me with this problem? I just want a post inside an iframe and only within the iframe, basically.

EDIT: After some more research, apparently the form is not being created properly. I'm using document.createElement("form") and then document.getElementById("my_iframe_id").appendChild(form) to append it, but it does not seem to be working correctly.

解决方案

Correct, because you are creating the form node in the current document.

document.getElementById("my_iframe_id").contentWindow.document.createElement('form');

to create it inside the iframe.

更多推荐

在iframe中发布表单

本文发布于:2023-10-11 17:43:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   iframe

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!