我需要能够在iFrame中打开指向特定URL的链接;该链接是由php生成的,并且我不能更改源代码,因此如果可能,我需要在iFrame中动态更改该链接。
我所做的是这样的:在一个非营利组织的网站上,我在页面的iFrame中显示了一个加盟店(由php生成),以使其与网站的其他部分更具风格化。php商店从一家附属服务公司获取产品;到store.php的链接与主要的非盈利网站在同一个域中。
问题是来自产品的最后一个“立即购买”链接打开了iFrame中的最终目的地电子商务商店,因此页面被卡在iFrame中,看起来很糟糕,用户必须滚动V和H才能查看和结帐。
我需要在新窗口中打开的链接总是有"av_buy_now“类,我可以访问CSS文件,我可以更改它。我可以访问PHP文件,即shop.php,但最终的链接似乎不是在本地生成的。我以这种方式显示iframe:
<iframe src="http://nonprofit.org/shop/mj/shop.php"></iframe>是否可以使用jQuery或Javascript找到包含该类的mydomain.com链接,并为其添加新的窗口属性?还是有更好的方法?谢谢
发布于 2011-02-28 04:27:12
没有一些代码,我不知道你的代码的确切结构,但我可以做到这一点。它要求jQuery也在iframe中。
$('iframe')[0].$('.av_buy_now').filter(function() {
return $(this).attr('href').indexOf('mydomain.com') > -1;
}).attr('target', '_blank');发布于 2011-02-28 04:50:44
你可以改变它,如果你能设法执行这种代码,改变类是有点麻烦的,如果你有一个id,可以这样做。
PAGE.html:
<button onclick="openinnewwin()">Get It</button>
<iframe src="test.html" id="ifrm"></iframe>
<script language="javascript">
function openinnewwin(){
ob=document.getElementById('ifrm');
if ( ob.contentDocument ) {
ob.contentDocument.getElementById('a').target="_blank";
}else if ( ob.contentWindow ){
ob.contentWindow.getElementById('a').target="_blank";
}
}
</script>test.html:
<a href="http://www.google.com" class="aaa" id="a">Hello</a>https://stackoverflow.com/questions/5135627
复制相似问题