好的,情况就是这样。我有一个我订阅的网站,可以让您添加自己的代码等。他们有一个论坛编辑器,我无法为我的网站设置皮肤,所以我只想更改最内层框架的颜色( doc3 在下面的示例中)。
这是基本设置...是的,所有文档都来自同一个域,但我只能将代码添加到主文档。doc3 框架是动态创建的。第一个框架有一个类但没有名称,第二个框架只有一个 id ...我不知道绑定是否适用于内部框架,但萤火虫没有给我任何错误。
哦,我也尝试过注入样式表,但没有成功。
主文档(我尝试访问 doc3)
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('iframe').bind('load', function(){
$(this).contents().find('body').css({'background-color':'#333333','color':'#ddd'}); // This does change doc2 colors
$(this).contents().find('iframe#doc3').bind('load', function(){
$(this).contents().find('body').css({'background-color':'#333333','color':'#ddd'}); // doesn't work :(
})
})
})
</script>
</head>
<body>
Document #1
<iframe class="postFrame" src="doc2.htm" width="100%" height="300">
</body>
</html>
doc2.htm
<html>
<head>
</head>
<body>
<form id="form1">
Document #2
<iframe id="doc3" src="doc3.htm" width="100%" height="250">
</form>
</body>
</html>
doc3.htm
<html>
<head>
</head>
<body style="background-color:#fff; color:#000;"> <!-- access this body style -->
Document #3
</body>
</html>
我希望我说得足够清楚。任何帮助或正确方向的一点将不胜感激:)
编辑:用 Wahnfrieden 的建议更新了主文档(谢谢!),但遗憾的是我仍然无法访问 doc3.htm