【发布时间】:2018-01-24 07:40:01
【问题描述】:
我试图从 iFrame 中删除的 CSS(phpbb 中的 colours.css)
html, body {
color: #536482;
background: url("../path/to/background.jpg") repeat-x #8fe909;
}
iFrame:
<iframe id="commentframe" scrolling="no" name="commentframe" onload="iframeLoaded()" src="/forum/viewtopic.php?f=13&t=10">
这也包含在一个名为 #commentdiv 的 div 中,只是为了更容易处理 span 区域。这里也是 iframe 加载的,虽然我认为这无关紧要,人们经常要求与正在进行的代码相关的任何内容
<script type="text/javascript">
function iframeLoaded() {
var iFrameID = document.getElementById('commentframe');
if(iFrameID) {
// here you can make the height, I delete it first, then I make it again
iFrameID.height = "";
iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight + "px";
}
}
</script>
据我了解,我需要使用 .has() jquery 函数通过在某处指定 CSS 类来完成此任务
.commentsbg {
background-color: transparent;
background: transparent;
}
那么 .has 的功能是这样的。
<script type="text/javascript">
$("body").has("iframe").addClass('commentsbg');
</script>
我也试过
<script type="text/javascript">
$("commentdiv").has("iframe").addClass('commentsbg');
</script>
以及在我的 .on('load', function)s 字符串中尝试它们。老实说,我对这些应该去哪里感到非常困惑。 js/jquery 是否进入 CSS 文件(这曾经发生过吗?)... CSS 是否进入 colours.css(iframe 的原始 css 文件)?我对这个很迷茫并且已经做了很长一段时间了。
【问题讨论】:
-
首先尝试在您的样式 css 文件中使用纯 css .. 尝试如下操作:
iframe>body{ background-color: red !important }用其他东西替换红色,如果这不起作用然后使用 js,重要的是是!important标志
标签: javascript jquery html css iframe