POST a form in an iframe.

Posted by Stavros Korokithakis on Stack Overflow See other posts from Stack Overflow or by Stavros Korokithakis
Published on 2010-06-08T21:00:18Z Indexed on 2010/06/08 22:12 UTC
Read the original article Hit count: 311

Filed under:
|
|
|
|

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:

http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit/134003#134003

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.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html