0

I would like to change the css from a iframe with jQuery. I used the following code:

Iframe:

<iframe id="myiframe" src="https://source.com"></iframe>

jQuery:

jQuery("#myiframe").contents().find("body").css('background-color', 'black');

But when I run the code, comes the following console error

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "https://example.com" from accessing a cross-origin frame.

Who has the solution to my problem?

Badslayer
  • 17
  • 5
  • 2
    Possible duplicate of [SecurityError: Blocked a frame with origin from accessing a cross-origin frame](http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame) – Robby Cornelissen Mar 20 '17 at 08:28
  • So it's not possible to change the css on the iframe? – Badslayer Mar 20 '17 at 08:33

1 Answers1

0

The iframe is not part of your page, so you can't change the style, you can apply styles just for iframe tag, for example to make a custom scrollbar etc.

Carnaru Valentin
  • 1,690
  • 17
  • 27