3

我想在iframe中动态设置head标签内的样式,以便在加载iframe本身时设置iframe正文上的类 ,比如我想应用ze_edit class iframe if this body :: ---在设置innerhtml时出现IE未知运行时错误

<head> 
<style type="text/css"> 
.ze_edit{font-family:Verdana,arial,Helvetica,sans-serif;font-size:12px;} 
</style> 
</head> 
<body class = "ze_edit"> 
</body> 

以下是样本测试文件的完整代码。

<html> 
<head> 
<script> 
test = function() 
{ 
var _style, 
_iframe, 
_doc, 
_head, 
ff, 
fs; 

ff = "georgia,times new roman,times,serif"; 
fs = "30pt" 
_doc = document; 
    _iframe = _doc.getElementsByTagName("iframe")[0]; 
    _iframe.contentWindow.document.designMode="on"; 
_style = _doc.createElement("style"); 
_style.type = "text/css"; 
_style.innerHTML = ".eclass{font-family:"+ff+";font-size:"+fs+"}"; 
_head = _iframe.contentWindow.document.getElementsByTagName("head")[0]; 
_head.appendChild(_style); 
_iframe.contentWindow.document.body.className = "eclass"; 
    } 
    </script> 
    </head> 
    <body> 
This is a just a test 
<iframe onload ="test()"> 
    satyam 
    </iframe> 
    </body> 
    </html> 

但这脚本在这条线抛出错误 “未知的运行错误” “* _style.innerHTML =” .eclass {字体家庭: “+ FF +”;字体大小:“+ FS + “} *”; “in IE。 此任何解决方法..

回答