Javascript 在iframe上隐藏动态元素
我有一个使用colorbox加载iframe(专有信息)的页面 我需要用一个特定的类在iframe中隐藏一个元素(加载需要几秒钟) 我试过了,但没有成功。控制台消息不会被点击。一旦它们被击中,我就可以使用jQuery css隐藏它们Javascript 在iframe上隐藏动态元素,javascript,jquery,css,iframe,colorbox,Javascript,Jquery,Css,Iframe,Colorbox,我有一个使用colorbox加载iframe(专有信息)的页面 我需要用一个特定的类在iframe中隐藏一个元素(加载需要几秒钟) 我试过了,但没有成功。控制台消息不会被点击。一旦它们被击中,我就可以使用jQuery css隐藏它们 $(function () { 'use strict'; $(".className").ready(function () { console.log("className on class ready");
$(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");
});
});
Colorbox初始化:
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方法(也不起作用):
.className.UITextTransformUppercase{
显示:无;
}
您的配色箱使用动态url来显示内容。在查找元素之前,必须确保已加载内容
您只需将属性设置为false
,并添加一个onComplete
处理程序,它就可以工作了:
$.colorbox({
href: previewLink,
iframe: true,
width: "90%",
height: "90%",
fastIframe: false,
onComplete : function() {
$('#cboxIframe').contents().find('.className').hide();
}
});
请验证您的配色箱iframe是否具有id
cboxIframe
。如果没有,请更新iframe选择器这是我过去的做法:
$('iframe.yourclass').load(function(){
$iframe = $('iframe.yourclass').contents();
$iframe.find('.class-selector').css('display','none');
});
但是,如果iframe在同一个域上,您不能编写简单的css来针对该元素。或者您没有访问css的权限?是否尝试使用普通css?页面是否在当前域中?如果否,则无法将
iframe
内的元素作为目标。页面位于同一个域中,但子域不同。如果可能,则必须将iframe内容作为对象作为目标。我把代码放在某个地方,我会把它贴出来。iframe是否有id或类?您是否尝试过在弹出窗口打开时将js display none添加到回调中<代码>onComplete:$(“.className”).css(“显示”、“无”)代码>此事件的触发时间比不使用FasticFrame选项要晚得多。但是,iframe尚未完成加载。previewLink是指向Office Web App预览链接的链接,Office Web App服务会处理该链接以显示预览。当id为动态id时,previewLink更改了colorbox框架以使用该类。现在我有一个“访问被拒绝”。这一定是一个跨子域的问题!是的,这似乎是一个跨域问题:。域中的两个子域是浏览器的两个不同主机…subdomain1.domain.com-我有权访问它。我在这里写了简单的CSS。加载的iframe来自subdomain2.domain.com,我无权访问它。我不确定是否有子域,但这里似乎有更多信息:
$('iframe.yourclass').load(function(){
$iframe = $('iframe.yourclass').contents();
$iframe.find('.class-selector').css('display','none');
});