There is a dynamically created iframe via js

var frame=document.createElement("iframe"); frame.setAttribute("src",url); frame.setAttribute("name",frameName); frame.setAttribute("id",frameName); frame.setAttribute("width","100%"); frame.setAttribute("height","100%"); frame.setAttribute("frameBorder",0); frame.isLoaded=false; document.body.appendChild(frame) 

Can I change the styles inside the frame using js or css?

  • from the outside - no way :) - Sublihim
  • @Sublihim, cheating is not good :) You can, but under security conditions - Yuri

1 answer 1

In the iframe, you can apply the style, if only in the iframe opens a page with the same domain on which the iframe itself is located . Otherwise, this is contrary to the rules of security Same-origin policy .

You can change any style in the iframe in one line:

 frame.contentWindow.document.ELEM.style.STYLE 

A live example: https://jsfiddle.net/yuri_spivak/gcujtjmp/

  • Thanks for the help - Alexandr Fomenko