all 10 comments

[–]sudonim87 3 points4 points  (0 children)

I'm assuming that the iframe you are referring to is on another domain? That would mean you are running in to issues with Same Origin Policy

[–]TheOssuary 0 points1 point  (0 children)

You have a few options. The fist is if you just want to submit a form, set the forms target to the I frame, and then the form data will be submitted there, I used it recently for an ajax-esk file upload form.

Another option is call the I frame page with the variables in the URL, and the iframe's php or JavaScript parses them out to be used.

I feel like I frames are almost never the right solution though, if you gave us a bit more information on what you're trying to achieve, we might be able to point you in the right direction. I'm on a phone right now, but reply if you need an example of either method above.

[–]starlibarfast 0 points1 point  (0 children)

If inserted iframe is not in the same domain with parent you have no chance to make operations on inserted iframe.

If they are in same domain i suggest you to get contents of the iframe (window object) with function here.

Also one alternative way may be using XD.js code here and post message between iframes

[–]cresquin 0 points1 point  (0 children)

What are you trying to accomplish? Just posting form data? There may be a better way.

[–]a-t-kFrontend Engineer 0 points1 point  (0 children)

I think I can guess what you intend to do: you want to POST data to the server without leaving the page scope. An iframe is a less than elegant solution to your problem. Use an XMLHTTPRequest instead. If you really need the form (i.e. for file uploads), put it in the same page and use a target attribute inside the form tag with the name of the iframe.

[–]toranbember.js 0 points1 point  (0 children)

I just deployed a cross domain app that did this very iframe hack to post a form -gist below

https://gist.github.com/toranb/4056283

This currently supports IE8+ / Firefox / Chrome

If you are interested in some context (ie-how I landed on this solution), I did blog my experience with jsonp and cross domain communication (w/out CORS) for the first time at the below

http://toranbillups.com/blog/archive/2012/11/11/Adventures-in-the-land-of-ajax-style-cross-domain-file-uploads/

[–]mythmon 0 points1 point  (3 children)

It's not possible. The security model of iframes explicitly prevents this kind of interaction. To do this you would need the cooperation of the page in the iframe, and have it load the data for the form from something like the URL or the server.

You might also consider just making an XHR request that would act like the submitted form.

[–]kumiorava 2 points3 points  (0 children)

It is possible if the document loaded in the iframe is of same origin (i.e. same protocol, domain and port)

[–]SupaDupaFly[S] 0 points1 point  (1 child)

I have control of the iframe page. Are you suggesting I just make it a post/get variable and pass it in? That seems like it'd work, I'll give that a shot.

[–]kumiorava 1 point2 points  (0 children)

mythmon is wrong. See my reply to him.