2011-05-28 69 views
2

我想设置iframe的HTML代码使用JavaScript设置,正常工作与Firefox和Chrome,但只显示的链接,而无需使用Internet Explorer 9的JavaScript IFRAME与innerHTML的Internet Explorer中

的JavaScript代码样式:

window.frames["iview"].document.body.innerHTML = txt; 

把txt变量得到下面的HTML代码:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <style type="text/css"> 
      a:link { 
       color: #0000C0; 
       background-color: #FFFFFF; 
       text-decoration: none; 
       target-new: none; 
      } 
      a:hover { 
       color: #0000FF; 
       background-color: #808000; 
       text-decoration: underline; 
       target-new: none; 
      } 
     </style> 
    </head> 
    <body> 
     <a href="http://www.domain.com">link....</a> 
    </body> 
</html> 

Internet Explorer中显示的链接,而不是CSS样式...

+0

你把所有上面的代码放入iframe的正文部分? – 2011-05-28 09:40:09

+0

是的,有没有办法设置头部以及? – Joe 2011-05-28 10:13:41

回答

1

堆栈溢出后How to apply CSS to iFrame?有帮助吗?

具体做法是:

嵌入在iframe页面的风格必须是通过将其包括在子页面设置:

<link type="text/css" rel="Stylesheet" href="Style/simple.css" /> 

或者,它可以从父页面的JavaScript加载:

var cssLink = document.createElement("link") 
cssLink.href = "style.css"; 
cssLink .rel = "stylesheet"; 
cssLink .type = "text/css"; 
frames['frame1'].document.body.appendChild(cssLink); 
+0

谢谢,我会尝试第二种建议的方法.. – Joe 2011-05-28 09:58:58

+0

只是想知道为什么它与FF和Chrome,而不是IE浏览器.. – Joe 2011-05-28 09:59:36