Doesn’t take any JavaScript or anything. You just have the form’s target attribute match the iframe’s name attribute.
<form action="iframe.php" target="my-iframe" method="post">
<label for="text">Some text:</label>
<input type="text" name="text" id="text">
<input type="submit" value="post">
</form>
<iframe name="my-iframe" src="iframe.php"></iframe>
The outer page doesn’t even reload. But it might appear to at first glance since many browsers run the page-loading spinner in the tab when an iframe reloads.
Aren’t iFrames a huge hassle/unnecessary/ugly and basically not used anymore?
sometimes a hassle. sometimes very useful and necessary. “frames” not so much.
Excellent ! Thanks a million !
When CORS is needed I frames could be a solution
Very useful for asynchronous posting files.
Another great little snippet, as much as i do hate iframes because of there restrictions i do like the ability to manipulate them for file uploads.
Strange, just can’t get this to work.
Uploaded a really basic page with just the form and the iframe page and it will not work.
http://www.mercury14.co.uk/asdfgh/form.php
Am I missing something obvious?
Does this show the content to everybody, or only to you on the one session?
I have the same problem. I created the iframe.php file, but nothing appears, whilst it does in the demo. Help please.
If anyone else is having problems making this work try this for the iframe.php page:
<p>I’m probably being loaded inside an iframe.</p>
<p>Text value: <?php echo $_POST[“text”]; ?></p>
Doesn’t work
You need to edit the < to the correct symbols:
That doesnt work either
That’s because to render < you use a semi-colon to delimit the code, not just & lt.
Right : & l t ; (remove spaces)
Wrong : & l t
Nice…!
Found this page while trying to solve this exact problem. I ended up using jQuery to build a GET query string and PHP to process it. I wanted to send data from a form on a page to a form in a fancybox iframe which is then submitted by AJAX – seems to work quite nicely.
Can you share how you did that? I’m trying to do the exact same thing. I have a form and when the user presses enter I want the php file to search for the data, and post to a fancybox iframe…
I recently used the same trick for an image uploader. I styled the file input by opacity:0 and its wrapper div with some nice looking image for the uploader button and its hover too. once the image is browsed or dragged, it is posted to the iframe and uploaded to the server and displays it in the seamless iframe just above it to show the resized and cropped image.
I’d love to write an article about it with all the code. All by HTML5, CSS3. I used js just to trigger form submit on change of file input.
I’m new to this and I’m having trouble.
I have a site with a css drop down menu that is 40px high, the menu content changes a lot so having the menu on each page would be a large hassle.
I’ve tried a iFrame for the menu, but the drop down parts of the menu are cut off by the iFrame. Is there a better way to do this or a trick to make the iFrame hover over the page content so the drop downs are viable?
Look up how to use PHP modularly; you use separate PHP files and load them together into one page that works like one file.
Once you edit the navigation, for example, it will be edited on all the pages.
This totally rocks!
Takes my php file and loads into an iframe without refreshing the page! EXACTLY WHAT I WAS HOPING FOR!
Thank you for posting this. You’ve just made one persons life much easier!
If you are generating the iframe on the fly on IE8, there is one special gotcha for this particular browser. You need to specify the name attribute inside your document.createElement method call:
var iframe;
try {
iframe = document.createElement('');
} catch (ex) {
iframe = document.createElement('iframe');
iframe.name = 'the-iframe-name';
}
otherwise, form upload will simply replace the current page.
more details:
http://terminalapp.net/submitting-a-form-with-target-set-to-a-script-generated-iframe-on-ie/
genial!
it works too with foreign domains in forms action and iframe src (like action=”http://anydomain.com/…”, src=”http://anydomain.com/…”, ie sort of bypassing same-domain-policy)
thanks lot!
i want to enter the register no in this frame….
plz help me….
i want to enter the register no in this frame….
iframe name=”frame1″ src=”http://103.4.221.147/srmwebonline/exam/onlineResult.jsp” height=”416″ width=”570″ frameborder=”0″>
plz help me..
This is just what I needed to post between two Drupal instances! Thank you!
Very Useful and simple snippet, thanks a lot..
I load an aspx page in iframe inside a jQuery UI dialog to update some data, and after dialog is closed I need to update an updatepanel in parent page. how can I do that? to be more specific, there is a datagrid in parent page and after I edit data in a dialog modal iframe, I want to update the row in datagrid.
Is the question how to write datagrid_selector or how to get the html you need in myHTMLVariable? I guess I kind of offered an answer for both there.
Can I use this solution while implementing YouTube’s browser based upload ? It seems all of the data is being handled on YouTube’s end, and I only find out if the upload was a success or failure when it’s complete.
Thank you.
I used similar code for file uploading, now i use flash instead. But it brings old memories back :).
I’m working on a real estate website that uses an iframe to bring in real estate listings. Is it possible to override some of the CSS that is responsible for styling the content of the iframe? I’m able to change it using Chrome dev tools but when I make the changes in the stylesheet, they are not applied. Any help is much appreciated.
Thank you SO much. That gives me exactly what I was looking for.
Brilliant,
Finally you saved me ! I was looking for such a simple code for my Facebook PageTab application in order to PHP_POST on my server & receive feedback form from our clients right on Facebook.
Thank you so much dude, and wish u luck
This code hits that action i.e., iframe.php 2 times in chrome and IE9, in mozilla the action got hit single time only.
please tell about this.
Admin Tell me a thing suppose i want to send a js(using textarea) code to some other cross domain server and get output via iframe i did the same and this thing works fine on Mozzila firefox but fails at Chromium ! what’s the matter in case of mozilla i get the required output of compiled js from server via iframe but when i try this in chromium no js code appears at iframe this is sick !
how can i upload both data and file together using ajax with all validations
And to access the response? (assuming you don’t have access to the code of the page being loaded in the iframe)
what should i put in the iframe.php?
can i use the same concept for 100% height as well as 100% width of the web page from whose iframe i want to create please help me..
This post saved my bacon. Many thanks.
When I try to do this, the website will show up in the iframe before the post data is sent, and once the post data is sent, it does not affect the content of the iframe. It’s like the iframe relies on it’s src command only and does not receive any post data from the action. Is there something I am missing here? Maybe something that is supposed to go inside the arbitrary PHP file other than a
…
$variable=$_POST[‘element’];
…
command?
I have a project that requires me to pass client names, addresses & dates into an embedded contract that is hosted is an iframe from a 3rd party (RightSignature). RightSignature is requiring text fields to show this data, but my client wants the names, address & dates to pass into placeholders in the contract (not text fields).
It would be really simple if it wasn’t in a 3rd party iframe. But, I’m also in agreement with my client… that there has to be a way to make this work, so the information will look more like:
Santa Claus 12/25/16
123 Reindeer Drive
North Pole, AK 12345
instead of the text fields requiring preset width parameters that are causing it to look like the following:
Santa Claus 12/25/16
123 Reindeer Drive
North Pole AK 12345
Thanks for your input… if you know how to bypass using RightSignature’s text fields in their 3rd party iframe!
This function creates a temporary form, then send data using jQuery:
target is the ‘name’ attr of the target iFrame, and data is a JS object :
data={last_name:'Smith',first_name:'John'}
how to use a iframe to popup a youtube video cause
i m useing like
path}}” frameborder=”0″ allow=”accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture” allowfullscreen>
this things but still refused toconnect
Does anybody have a problem with this approach in Chrome 83?
Described process:
* in common case here https://alfilatov.com/posts/how-to-pass-data-between-iframe-and-parent-window/
* and in case of file transferring https://alfilatov.com/posts/how-to-pass-file-into-an-iframe-and-convert-it-to-blob-for-further-ajax-request/