简体   繁体   English

如何在用户点击时更改iFrame中的src?

[英]How to change src in iFrame on user clicks ??

I am a newbie with coding php or js. 我是编码php或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. 我希望能够将URL地址从链接传递并嵌入到iFrame的src =“在此处嵌入的URL”中。 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. 带有链接的页面上带有显示有公司名称的链接,用户将单击该链接,然后将显示一个新的.php页面,其中包含一个iFrame,其中显示了该公司在我们网站中的实际网站。 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. 因此,例如...在索引页面上,用户单击“ Goodyear”,它将启动一个.php页面,其中包含在iFrame中显示的Goodyear网站。 Now... I have about 20+ vendor links and am trying to avoid 20+ individual html or php pages to display that data. 现在...我大约有20多个供应商链接,并且正在尝试避免20多个单独的html或php页面来显示该数据。 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; 我所指的页面是http://seindl.com/index.php ,您可以在href元素中看到相应的URL。 and the resulting linked to page http://seindl.com/vendor.php that currently displays a static Kuriyama.com website. 并链接到http://seindl.com/vendor.php页面,该页面当前显示静态的Kuriyama.com网站。

Well if you have list of links, you do not need jquery or javascript to change the iFrame src. 好吧,如果您有链接列表,则不需要jquery或javascript来更改iFrame src。 For example, if you have iframe like this: 例如,如果您拥有这样的iframe:

<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 ). 将在iFrame中打开页面(基于链接的target属性,该属性必须与iframe name匹配)。

If you really need to do it with jQuery, you can try something like: 如果您确实需要使用jQuery,可以尝试执行以下操作:

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

Or with javascript without libraries: 或使用不带库的javascript:

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: 将供应商ID应用于网址,如以下index.php页面上所示:

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. 然后在vendor.php文件上,基于id(使用$ _REQUEST ['id']获取ID),您可以放置​​供应商的url。

$id =  $_REQUEST['id'];

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

....

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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