2016-09-06 115 views
0

我的页面上有一个iFrame,它是从外部源进入的,当iFrame被加载时,它会自带'样式类,我试图删除其中的一个类。因此,当iFrame中加载HTML看起来像这样:删除iFrame的html标签的样式

<iframe style="background-color:#fff !important" id="myFrame" src="http://salonspy.co.uk/widget?i=72108" frameborder="0" height="270" width="320"> 
#document 
    <html> <!---THIS IS THE TAG I'M TRYING TO GET A HANDLE ON!--> 
     <head>...</body> 
     <body>...</body> 
    </html> 
</iframe> 

HTML标记应用了背景颜色(由外部CSS),我试图消除这种背景色(或应用透明一个),但我似乎无法得到这个标签的“保留”。

我有一些等待加载iFrame的jQuery,但我不知道该如何应用这种新样式。

$(function() { 
$("#myFrame").bind("load",function(){ 
    //$(this).contents().find("[tokenid=" + token + "]").html(); 
    alert("iFrame loaded"); 
    //$(this).contents().find("html").css("background-color","white"); 
    var src = $('#myFrame>html').html(); 
    alert(src); 
}); 
}); 

请问有人能协助吗?

谢谢。

+1

如果您是从same origin内访问salonspy.co.uk,您可以通过调用内部HTML访问HTML内容你说这是从一个“外部来源”(我可以告诉的salonspy.co.uk)。如果iframe在salonspy.co.uk之外托管,则可能会遇到[同源策略](https://en.wikipedia.org/wiki/Same-origin_policy)的问题。请参阅[此接受的答案](http://stackoverflow.com/a/364997/6697953)。 –

+1

[jQuery/JavaScript:访问iframe的内容]的可能重复(http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) –

+0

这告诉我如何获得一个命名的元素,但不是通用的HTML标记 – SxChoc

回答

0

从评论移到回答。

普通的JavaScript

document.getElementById('myFrame').contentWindow.document.bo‌​dy.innerHTML 

jQuery的

$('#myFrame').contents().find("html").html();