Add CSS to iFrame [duplicate]

Based on solution You’ve already found How to apply CSS to iframe?:

var cssLink = document.createElement("link") 
cssLink.href = "https://stackoverflow.com/questions/6960406/file://path/to/style.css"; 
cssLink .rel = "stylesheet"; 
cssLink .type = "text/css"; 
frames['iframe'].document.body.appendChild(cssLink);

or more jqueryish (from Append a stylesheet to an iframe with jQuery):

var $head = $("iframe").contents().find("head");                
$head.append($("<link/>", 
    { rel: "stylesheet", href: "https://stackoverflow.com/questions/6960406/file://path/to/style.css", type: "text/css" }));

as for security issues: Disabling same-origin policy in Safari

Leave a Comment