Last active
December 24, 2015 07:59
-
-
Save make-sum/6767747 to your computer and use it in GitHub Desktop.
Get iframe by ID and append a CSS style to affect an element inside the iframe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var iframe1 = document.getElementById('myiframeID'); | |
iframe1.onload = function (){ | |
if(this.contentDocument) iframe1.doc = iframe1.contentDocument; | |
else if(iframe.contentWindow) iframe1.doc = iframe1.contentWindow.document; | |
var css = '.myelement{float:right;}', | |
header = iframe1.doc.getElementsByTagName('head')[0], | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
if (style.styleSheet){ | |
style.styleSheet.cssText = css; | |
} else { | |
style.appendChild(document.createTextNode(css)); | |
} | |
header.appendChild(style); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment