[英]HTML Renders in IE7 but not in Firefox or Chrome
The following html in an <iframe>
renders in IE7 but not in Firefox or Chrome? <iframe>
的以下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 >
dynamicFormIframe = (dynamicFormIframe.contentWindow) ? dynamicFormIframe.contentWindow : (dynamicFormIframe.contentDocument.document) ? dynamicFormIframe.contentDocument.document : dynamicFormIframe.contentDocument;
contentDocument.document
is nonsense; contentDocument.document
是废话; that clause will never be taken. 该条款将永远不会被采用。 Chrome, not supporting the non-standard
contentWindow
property, will fall back to using contentDocument
, which is a different object from contentWindow
. Chrome浏览器不支持非标准的
contentWindow
属性,但会退回到使用contentDocument
,它是与contentWindow
不同的对象。
You only seem to want the document, not the window, so go for the standard contentDocument
first, and only fall back to going via the window for IE where it's not supported: 您似乎只想要文档,而不是窗口,因此请先使用标准
contentDocument
,然后仅回退到不支持IE的窗口:
var iframe= document.getElementById('dynamicFormIframe');
var idoc= 'contentDocument' in iframe? iframe.contentDocument : iframe.contentWindow.document;
idoc.open();
idoc.write(content);
idoc.close();
(Your example also has many apparent typos like mismatching tags, a JS string split over lines and a malformed doctype, is that a copy-and-paste error?) (您的示例还存在许多明显的拼写错误,例如标签不匹配,JS字符串分割成行以及格式错误的文档类型,这是复制粘贴错误吗?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.