Injecting stylesheet into an iFrame
Ran from local host and am no longer getting the error (duh). But it still isn't working.
I figured it out. Kind of. For some reason it is only attaching it to my last iframe though. It skips everything else in the array and only injects it into the last iframe?
<script type="text/javascript">
function injectStyle(name){
cssLink = document.createElement("link")
cssLink.href = "http://localhost/~arronhunt/idethemes/themes/"+name+".css";
cssLink.rel = "stylesheet";
cssLink.type = "text/css";
// Grabs all the iframes on the page
frames = document.getElementsByTagName('iframe');
var theFrame
for(var i in frames){
// Sometimes i returns 'length'. WTF
if(i == 'length'){ return }
// Assigns a variable to the iFrames document
theFrame = frames[i].contentWindow.document;
// Cleans out anything in the <head> of the iframe
theFrame.getElementsByTagName('head')[0].innerHTML='';
// Injects the CSS
theFrame.getElementsByTagName('head')[0].appendChild(cssLink);
// Log them so I can see if it failed.
console.log(theFrame);
}
}
</script>






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None

















Help