/    Sign up×
Community /Pin to ProfileBookmark

Passing Variables from Main Page to iFrame

Hi everyone,

I am having lots of trouble here. I tried searching google for a good hour +, and I simply cannot find anyone that gives a good example or what I am looking for.

Here is what I am trying to accomplish:

I have an iFrame located on a page, we’ll call it mainpage.php. The iframe is iframe.php. I am trying to make an <a> tag, or a submit button (whichever is easier, doesn’t matter to me) that when you click it, it passes a variable from mainpage.php to the iframe.php. This should cause the iframe.php to refresh, using the data that was passed to it from mainpage.php. However, mainpage.php should not refresh, only the iframe (iframe.php) should.

Any little bit would help. Thanks.

-webDevShane

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 28.2008 — You don't really need any PHP for this. Just define the link with a URL query string to pass the desired values, and then use the "target" attribute to target the IFrame. The PHP page in the IFrame would then receive the values via the $_GET array.
<i>
</i>&lt;a href='iframe_page.php?var1=value1&amp;var2=value2' target='iframe_name'&gt;Click
me&lt;/a&gt;

&lt;iframe name='iframe_name' src='iframe_page.php'&gt;&lt;/iframe&gt;

Of course, you could use PHP to control the actual values used in the query string.

Alternatively, you might want to consider not using IFrames at all, and look into an "AJAX" solution using JavaScript to call a PHP file on the server and then update the page contents based on what it receives.
Copy linkTweet thisAlerts:
@webDevShaneauthorJul 28.2008 — Hey this was exactly what I needed, thanks.
×

Success!

Help @webDevShane spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...