【发布时间】:2018-04-22 20:30:56
【问题描述】:
如何在 iFrame 最内层的 body 标签内使用 JavaScript 设置最外层的 body 标签的样式?
<html>
<head>
</head>
<body>
<div id="ad_tag" style="width: 1px; height: 1px;">
<div id="ad_container" style="border: 0pt none;">
<iframe id="ad_iframe" title="title" name="name" scrolling="no" marginwidth="0" marginheight="0" style="border: 0px none; vertical-align: bottom;" srcdoc="" width="1" height="1" frameborder="0">
<html>
<head>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<script>
parent.document.body.style.background = "url('https://news.nationalgeographic.com/content/dam/news/photos/000/676/67655.jpg') no-repeat top center fixed #ffffff";
</script>
</body>
</html>
</iframe>
</div>
</div>
<div id="content">
</div>
</body>
</html>
- 在这种特定情况下:
- 不允许直接编辑属性或样式,现有的都是预设的。
- 只能编辑最内层主体的子元素。
- 目标是使用 Google DFP 提供背景图片。
【问题讨论】:
-
iframe是否有权限访问父文档?
-
@CertainPerformance,是的。
标签: javascript css iframe google-dfp skin