The following html in an <iframe>
renders in IE7 but not in Firefox or 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>"
<scr开发者_JAVA技巧ipt>
.....
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; 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
.
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:
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?)
精彩评论