views:

8

answers:

1
var content = "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.2//EN\"\"http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd\"&gt;
<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 >

not able to show html content in chrome and ff but works well in IE7

A: 
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?)

bobince

related questions