2011-05-28 44 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