简体   繁体   English

IE7中的HTML渲染,但Firefox或Chrome中没有

[英]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.

相关问题 HTML和CSS在Chrome和Firefox中可以正常工作,但在IE7上却不能 - HTML and CSS works fine in Chrome and Firefox but not IE7 可以在Chrome和Firefox中正确渲染,但不能在Safari或IE中渲染 - Renders properly in Chrome and Firefox, but not in Safari or IE 使用 HTML5 播放器在 ie7,8,9 firefox、chrome 和 safari 中播放 mp4 视频 - 可能吗? - play mp4 video in ie7,8,9 firefox, chrome and safari using the HTML5 player - possible? 2个链接+按钮在IE7 / 8/9中无法正确定位,就像在Chrome / Firefox中一样 - 2 Links + Button not positioning correctly in IE7/8/9 like they do in Chrome/Firefox IE7与Firefox / Opera / Chrome之间的间距差异 - Spacing differences between IE7 and Firefox/Opera/Chrome HTML格式-iframe无法在Firefox中运行,但可以在IE7中运行 - Html form - iframe not working in firefox but works in IE7 简单的html页面在Firefox和IE中呈现的方式有所不同。 如何解决? - Simple html page renders differently in Firefox and IE. How to fix it? html d3.js,图像在Firefox中呈现,但不在chrome中呈现 - html d3.js, image renders in firefox but not in chrome Wordpress 导航栏呈现不正确 IE7 - Wordpress nav bar renders incorrectly IE7 HTML IE条件声明:不适用于Chrome / Firefox - HTML IE conditional statement: Not working with Chrome/Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM