将Css从第三方注入iframe [英] Inject Css into iframe from third party

查看:317
本文介绍了将Css从第三方注入iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以将一堆CSS文件从像OAS这样托管广告的第三方注入iframe吗?如果有可能,我将非常感谢一个例子。

Can we inject bunch of CSS files into an iframe from a third party like OAS which is hosting ads? If it is possible an example will be greatly appreciated.

推荐答案

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

By using jQuery selectors, you should be able to do that. However there should not be any restriction on iframe contents (i.e it should be from same domain)

对于HTML更新:

$('iframe')。contents()。find(body)将获取您的身体对象

$('iframe')。contents()。find(head)将获得标题对象。你可以在这里添加样式

$('iframe').contents().find("head") will get you header object. You can add style here

请参阅本教程了解详情

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

and this

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

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

If the iframe is from different domain then it is not possible due to http://javascript.info/tutorial/same-origin-security-policy

这篇关于将Css从第三方注入iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆