隐藏iframe中的元素 [英] Hide elements in iframe
问题描述
我有一个iframe(相同的域名),我隐藏了一些我不想从这个iframe显示的元素。一切正常,但是当我点击一个ul> li列表并选择这个列表中的一个项目时,隐藏的元素会再次显示。
I have an iframe (same domain) and I'm hiding some elements I don't want to display from this iframe. Everything works, but when I click on a ul > li list and I select an item of this list, the hidden elements display back again.
iframe不会更改隐藏系统的ID或类似的东西,所以我不知道为什么隐藏的系统会再次显示。
The iframe don't change the ID of the hidden ítems or anything like that so I don't know why the hidden ítems display again.
我现在的解决方案是一个setInterval, ítemshidden,但它会在网页停顿几分钟后让页面变得糟糕,所以我需要另一个解决方案。
The solution I have right now is a setInterval that keep the ítems hidden but It colapses the page after some minutes inactive in the page so I need another solution.
我尝试了类似iframe中的检测点击功能,但是当我
I tried something like detect a click function inside the iframe, but when I select a item of the list this function don't work more.
$(function(){
var f=$('#iframe')
f.load(function(){
f.contents().find("#____bl_k_dd").on('click', function(event) {
runAfterTimeout();
});
});
});
function runAfterTimeout() {
setTimeout(function(){
alert("hi its me");
$('#iframe').contents().find('body').css("background", "green");
},2000);
};
我尝试检测元素上的点击函数,它第一次运行, t Works。
I try to detect a click function on the element, it Works the first time, then it don't Works.
如果我将元素的ID更改为body,它有时只是有效,所以它不是解决方案。
If I change the ID of the element to body it Works just sometimes so it's not a solution.
推荐答案
您可以创建一个css文件并将其添加到您的iframe页面中。
You can create a css file and add it to your iframe page
var $head = $("iframe").contents().find("head");
$head.append($("<link/>",
{ rel: "stylesheet", href: "file://path/to/style.css", type: "text/css" }));
这篇关于隐藏iframe中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!