【发布时间】:2015-06-26 21:50:21
【问题描述】:
我有一个使用 colorbox 加载 iframe(专有信息)的页面。
我需要在 iframe 中隐藏一个带有特定类的元素(需要几秒钟才能加载)。
我试过这个没有成功。控制台消息未命中。一个他们被击中,然后我可以使用 jQuery css 隐藏它们。
$(function () {
'use strict';
$(".className").ready(function () {
console.log("className on class ready");
$(".className").css("display", "none");
});
$(document).on("ready", ".className", function () {
console.log("className on document ready");
$(".className").css("display", "none");
});
});
彩盒初始化:
function ShowColorbox(fileId) {
'use strict';
var colorboxUrl = getColorBoxUrl();
$.ajax({
type: "GET",
url: colorboxUrl,
dataType: "json",
timeout: 30000,
success: function (previewLink) {
$.colorbox({ href: previewLink, iframe: true, width: "90%", height: "90%" });
},
error: function (jqXhr, textStatus, errorThrown) {
alert("failed");
},
complete: function () {
// Do nothing
}
});
}
纯 CSS 方法(也不起作用):
<style>
.className .UITextTranformUpperCase {
display: none;
}
</style>
【问题讨论】:
-
你尝试过使用纯 CSS 吗?
-
页面是否在当前域中?如果不是,那么您不能定位
iframesame origin policy 中的元素 -
页面在同一个域但不同的子域
-
那么是可能的,但是您必须将 iframe 内容定位为对象。我在某个地方有代码,我会发布它。 iframe 是否有 id 或类?
-
您是否尝试将 js display none 添加到弹出窗口打开时的回调中?
onComplete: $(".className").css("display", "none");
标签: javascript jquery css iframe colorbox