Inject Css into iframe from third party

折月煮酒 提交于 2019-12-22 08:23:20

问题


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.


回答1:


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)

For HTML update:

$('iframe').contents().find("body") will get you body object

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

Please refer this Tutorial for details

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

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



来源:https://stackoverflow.com/questions/35188324/inject-css-into-iframe-from-third-party

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!