2010-07-28 119 views
0

中的以下html呈现在IE7中,但不会呈现在Firefox或Chrome中?HTML在IE7中呈现,但不在Firefox或Chrome中呈现

var content = "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.2//EN\"\"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd\"> 
<html> 
<body style=\"background-color:#0C0C0C; color:#FFFFFF\"> 
Please Enter the credentials 
<form name=\"dynamicform\"> 
<ul class=\"edgetoedge\" style=\"background-color:#0C0C0C;\"><li><div id=\"errorDiv\" style=\"color:red\"> </div></li> <li> <input id=\"Phone Number:_minLength\" type=\"hidden\" value=\"16\" /> </li> 
<li> </ul> </form> </body> </html>" 
<script> 
..... 
var dynamicFormIframe = document.getElementById('dynamicFormIframe'); 
dynamicFormIframe = (dynamicFormIframe.contentWindow) ? dynamicFormIframe.contentWindow : (dynamicFormIframe.contentDocument.document) ? dynamicFormIframe.contentDocument.document : dynamicFormIframe.contentDocument; 
     dynamicFormIframe.document.open(); 
     dynamicFormIframe.document.write(content); 
....</sript> 
<body><iframe id="dynamicFormIframe" src=""></frame></body > 

回答

0
dynamicFormIframe = (dynamicFormIframe.contentWindow) ? dynamicFormIframe.contentWindow : (dynamicFormIframe.contentDocument.document) ? dynamicFormIframe.contentDocument.document : dynamicFormIframe.contentDocument; 

contentDocument.document是无义;该条款将永远不会被采纳。不支持非标准contentWindow媒体资源的Chrome将回退到使用contentDocument,这是与contentWindow不同的对象。

你只能似乎要的文档,没有窗户,所以要为标准contentDocument第一,只有回落到通过IE浏览器的窗口,它不支持去:

var iframe= document.getElementById('dynamicFormIframe'); 
var idoc= 'contentDocument' in iframe? iframe.contentDocument : iframe.contentWindow.document; 
idoc.open(); 
idoc.write(content); 
idoc.close(); 

(你的榜样也有很多明显的拼写错误,如不匹配的标签,一个JS字符串分割线和格式错误的doctype,是复制和粘贴错误?)