简体   繁体   中英

How to change src in iFrame on user clicks ??

I am a newbie with coding php or js. So please advise me if I am asking the question the wrong way.

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.

Well if you have list of links, you do not need jquery or javascript to change the iFrame src. For example, if you have iframe like this:

<iframe name="frame1" id="frame1" src="about:blank"></iframe>

Simply creating links like this:

<a href="http://something.com" target="frame1">LINK</a>

will open the page in iFrame (based on target attribute of the link, which must match the iframe name ).

If you really need to do it with jQuery, you can try something like:

$('#frame1').attr('src','http://something.com');

Or with javascript without libraries:

document.getElementById('frame1').src = 'http://something.com';

Which will also change the page open in the frame.

Appned id of vendor to the url like below on index.php page:

vendor.php?id=10

And then on vendor.php file, base on the id (use $_REQUEST['id'] to get id) you can put the url of the vendor.

$id =  $_REQUEST['id'];

if($id == 10){
$vendorSiteUrl = "http://vendorsiteurl.com";
}

....

<iframe src="<?php echo $vendorSiteUrl;?>"/>

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM