4

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.

user747291
  • 821
  • 3
  • 20
  • 43

1 Answers1

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

Thangaraja
  • 926
  • 6
  • 20
  • [Consider adding more content to your answer.](http://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/8259#8259) – Litty Feb 03 '16 at 21:49
  • This is example of the iframe on the same domain....I need some insight on whether CSS file can be injected into an iframe from a third party – user747291 Feb 03 '16 at 21:56
  • 2
    Not possible if it is from different domain. Updated the answer – Thangaraja Feb 03 '16 at 21:59