Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


how to dynamically change url content displayed in iFrame when user clicks link

I would like to be able to pass and embed URL address from a link into the src="URL embedded here" of an iFrame. The page with the link has links with a company name displayed, the user will click the link and a new .php page will be displayed with an iFrame that displays the actual website of that company within our site. So... for example... on the index page, the user clicks "Goodyear" and it launches a .php page containing the Goodyear website displayed within the iFrame. Now... i have about 20+ vendor links and am trying to avoid 20+ individual html or php pages to display that data. Especially since the vendor list will change often. Any assistance would be greatly appreciated. The pages that I am referring to are http://seindl.com/index.php where you can see the appropriate URL's in the href elements; and the resulting linked to page http://seindl.com/vendor.php that currently displays a static Kuriyama.com website.

2 Answers

Use a get variable. Your URL could look something like this:


You could access that variable and put an iframe like this:

<iframe src="clients/<?php echo $_GET['name']; ?>/"></iframe>

This would turn into this after being processed:

<iframe src="clients/treehouse/"></iframe>

That way depending on the variable, the iframe will display the contents of the folder which name is equivalent to the variable's value. Is this what you are asking for?

Yes, thank you for your time and clear explanation.