我正在尝试为EtherPad网站构建一个印刷的chrome plguin。问题是我不知道如何使用jQuery删除etherpad中<body>
内的iframe
中iframe
的内联css
如果你打开一个以太网文档,让我们说http://typewith.me,就会有这样的HTML:
<body id="innerdocbody" class="syntax safari authorColors doesWrap" spellcheck="false" contenteditable="true" style="font-family: Arial, sans-serif; font-size: 13px; line-height: 17px; ">
我只需要使用jQuery删除style属性。 (我是一个CSS人,jQuery的新手)
答案 0 :(得分:0)
$('body', $('iframe#yourIframeID').contentDocument).removeAttr('style');
答案 1 :(得分:0)
如果您需要在iframe中运行内容脚本,则需要在清单中启用all_frames
标志。关于它的更多信息here。
答案 2 :(得分:0)
刚刚编写了一个快速函数,它将在文档的所有iframe中递归执行getElementById,并返回它找到的第一个。
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;
}
}
}
有了这个,您可以使用以下代码从#innerdocbody
中删除styleAttributegetElementByIdInFrames("innerdocbody", window).removeAttribute('style');