I am trying to build a typographical chrome plguin for EtherPad sites. Problem is I don't know how to remove inline css of <body>
in iframe
within an iframe
on etherpad using jQuery
If you open an etherpad doc, let's say on http://typewith.me, there is html that goes like:
<body id="innerdoc开发者_如何学编程body" class="syntax safari authorColors doesWrap" spellcheck="false" contenteditable="true" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 17px; ">
I just need to remove style attribute using jQuery. (I am a CSS guy, new to jQuery)
$('body', $('iframe#yourIframeID').contentDocument).removeAttr('style');
If you need to run a content script inside iframes you need to enable all_frames
flag in the manifest. More about it here.
Just wrote a quick function that will do a getElementById in all the iframes in the document, recursively, and return the first one it finds.
function getElementByIdInFrames(id, base) {
var el;
if(el = base.document.getElementById(id)) {
return el;
}
for(var i = 0, len = base.frames.length; i < len; i++) {
if(el = getElementByIdInFrames(id, base.frames[i])) {
return el;
}
}
}
With this, you can use the following code to remove the styleAttribute from #innerdocbody
getElementByIdInFrames("innerdocbody", window).removeAttribute('style');
精彩评论