简体   繁体   English

如何使用CSS更改iframe src

[英]How to change iframe src using css

I am trying to remove ads from my profile on a website, so I don't have access to the original css or code, but there is still the ability to change the css code by editing the profile. 我试图从网站上的个人资料中删除广告,因此我无权访问原始的CSS或代码,但是仍然可以通过编辑个人资料来更改CSS代码。

For example I have added these lines: 例如,我添加了以下几行:

<style type="text/css"> 
.topad {display:none; visibility:hidden;}
#buyers_ad {display:none; visibility:hidden;}
</style>

which removes an advertisement from the top and right side of the page. 从页面的顶部和右侧删除广告。

The problem is that there is an iframe that points to an advertisement. 问题在于,有一个指向广告的iframe。 Is it possible to change the src that the iframe points to using css, but not html? 是否可以使用css更改iframe指向的src,但不能更改html? The iframe does not have a class or id. iframe没有类或ID。

It's an iframe inside a div, if that is helpful. 如果有帮助,它是div中的iframe。

You can make iframe hidden using css 您可以使用CSS隐藏iframe

Html: HTML:

<div id="somediv">
<iframe .... />
</div>

css: CSS:

<style type="text/css"> 
#somediv > iframe { display : none}
</style>

Or you can also change src of iframe using Jquery / JS 或者您也可以使用Jquery / JS更改iframe的src

Html: HTML:

<div id="somediv">
<iframe .... />
</div>

Jquery: jQuery的:

$('#somediv iframe').attr('src','http://google.com');

Hope It Helps You.. :) 希望对您有帮助.. :)

使用jQuery thats更好的选择来隐藏

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

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