4

我们可以将一堆 CSS 文件从托管广告的 OAS 等第三方注入到 iframe 中吗?如果可能的话,一个例子将不胜感激。

4

1 回答 1

1

通过使用 jQuery 选择器,您应该能够做到这一点。但是,对 iframe 内容不应该有任何限制(即它应该来自同一个域)

对于 HTML 更新:

$('iframe').contents().find("body")会得到你的身体对象

$('iframe').contents().find("head")会给你标题对象。您可以在此处添加样式

详情请参考本教程

http://code.tutsplus.com/tutorials/how-to-inject-custom-html-and-css-into-an-iframe--net-22826

和这个

https://github.com/NETTUTS/Inject-HTML-and-CSS-into-iFrame/blob/master/iframe.html

如果 iframe 来自不同的域,那么由于http://javascript.info/tutorial/same-origin-security-policy是不可能的

于 2016-02-03T21:46:18.703 回答