Code Snippet
Post Data to an iframe
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.
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.
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..
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.