473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Sending a value to an iframe

KeredDrahcir
426 256MB
I have a php program that uses a POST value to start it. I want to run the program my other website using an iframe. I have a form linking to the page the runs the iframe using a POST method. I there anyway to get the iframe to read the post rather than it's parent?

Otherwise is there a way to send a value to and iframe using JavaScript that the iframe will read as a POST value?

If neither of these are possible, is there any other way or will I have to create another copy of the program that is suited to start from the iframe.
If I have to do this, is there a way that the iframe can detect the parent page that is running it so that I can disable the program unless the parent is my website to stop people hijacking the link?
Jun 10 '12 #1
2 7448
Aimee Bailey
197 Expert 100+
Although the iframe tag makes itself out to be part of the regular DOM (document object model), it actually is more like an entirely new web-browser within your page. Because of this it is restricted by the cross-domain policy issue that causes many people headaches when trying to use the tag. This may not seem an issue at first, but if you try to use javascript to access the 2nd DOM within the iframe, you'll find a security exception is thrown.

Also PHP code executes on the server only, by the time the web-page is displayed, the PHP script has finished running, and the result has been downloaded to the web-browser. POST variables are not sent to the web-browser, so no you can't pass them to an iframe via javascript.

An answer to your situation is that you can actually achieve what you want by passing a posted variable as a GET style variable into the src of the iframe tag like so:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.   $url = 'sub_page.php?a=' . $_POST['a'];
  3.   // Do some validation here.
  4. ?>
  5. <iframe src="<?php echo $url; ?>"></iframe>
  6.  

It should be noted though, if you use this work-around, users to your site will be able to see the variable in the source code, also I've left a comment in there to remind you that you should always validate incoming variables to make sure they are not malicious.

Hope this helps!

Aimee.

---------

Edit: just saw that you had already posted another question about this a few weeks ago but got no replies, I know GET variables may not be the perfect answer, but when using the iframe tag, and all the quirks that come with it, the most consistently reliable method is to pass the variable to the src tag attribute, it should also be noted however that POST vars within the iframe itself stay in scope (if that helps).

Lastly have you considered ditching the iframe tag all together? if it's just scrolling and dynamic content loading you want, you can achieve that with a little bit of ajax and a div with scroll bars, which would remove this problem all together.

Aimee.
Jun 17 '12 #2
KeredDrahcir
426 256MB
Thanks. I did consider putting $_GET content within the src but the reason I wanted to use $_POST was so that it was hidden.
I have some JavaScript that detect what the parent is so I might use php to set the variable if the parent is correct.

The iframe is included because I have a php program running in it but I want it to blend in with the page. I have adjusted the program and saved it with a different name for use within the frame.

Thanks for your help. If I have trouble with the JavaScript I have I may be back but I'll keep you posted on what I do.
Jun 18 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ToMeK | last post by:
Hi! i have php page that displays records from mysql base. on that page i have link like this: <a href="mypage.php?option1">option1</a> ("option1" is name of one of my tables in db) now...
1
by: efiedler | last post by:
Hi - I have the following input field on my html page: <input type="image" name="submit" id="submit" src="c:\image.jpg" value="image.jpg"> I also have another input field on the form that is...
2
by: Csaba2000 | last post by:
I want to be able to embed a single quote into an INPUT element within a dynamically generated IFRAME. The example below shows how the IFRAME is generated. Challenge: I'd like the alert box to...
5
by: Dominic | last post by:
Hi everybody, My goal is to set the height of the iframe to fit its content. There was an earlier posting which gave some useful insights. ...
15
by: Aaron Gray | last post by:
<iframe name="iframe" width="100%" height="25%" src="test1.txt"> </iframe> <a href="test1.txt" target="input">one</a> <a href="test2.txt" target="input">two</a> <form name="form1"> <textarea...
2
by: Jeff | last post by:
Hey asp.net 2.0 I wonder what C# code I need to send a value from one user control to another user control on the same webpage? Maybe some of you have a link to a great example covering this...
4
by: Sofia | last post by:
Hi there is text field and a button.... now i have to send this textfield value to another page without using form tag......i have to use javescript... is there anyone who can help me regarding...
14
by: Sofia | last post by:
Hi there is text field and a button.... now i have to send this textfield value to another page without using form tag......i have to use javescript... is there anyone who can help me regarding...
3
by: Sirix42 | last post by:
Hi there, when I use Firefox to run my application (this involves sending an IFRAME request to the servlet and handling the response), there is no delay in displaying the data after each response....
2
by: mkhines | last post by:
I'm having trouble figuring out the proper way to pass this variable in with javascript alone. I'm not used to not being able to use jsp and all the love that is in that. Obviously I know...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.