设置innerhtml时IE未知的运行时错误

时间:2011-11-25 09:51:16

标签: javascript internet-explorer loading innerhtml runtime-error

我正在尝试在iframe中动态设置head标签内的样式,以便设置类 加载iframe本身时iframe的主体,说我想应用ze_edit iframe体上的类就像这样:: ---

<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 {font-family:“+ ff +”; font-size:“+ fs +”} * “; “在IE中。 解决此问题的任何解决方法..

1 个答案:

答案 0 :(得分:0)

这可能是一些IE错误/功能。在这篇文章中这样做:

How to change/remove CSS classes definitions at runtime?