Build HTML document with jQuery to set it in iframe

Build HTML document with jQuery to set it in iframe

 am receiving from server full HTML code of different pages as string:

 $.post($form.attr("action"), $form.serialize(), function(responseText) { console.log("text received"); //Setting dynamic content to iframe method * }).error(function(p1, p2, p3){ alert("error!"); console.log(p1 + p2 + p3); })

;

Setting dynamic content to iframe method 1:

var s = $(responseText); $('#FileFrame').contents().find('html').html(s);

Setting dynamic content to iframe method 2:

var $frame = $('#FileFrame'); var doc = $frame[0].contentWindow.document; var $body = $('body',doc); $body.html(responseText);

Setting dynamic content to iframe method 3:

var iframe = document.getElementById('FileFrame'); var iframedoc = iframe.document; if (iframe.contentDocument) { iframedoc = iframe.contentDocument; console.log("iframe has contentDocument"); } else if (iframe.contentWindow) { iframedoc = iframe.contentWindow.document; console.log("iframe has contentWindow.document"); } if (iframedoc) { //iframedoc.open(); iframedoc.write(responseText); iframedoc.close(); console.log("iframedoc is not NULL"); } else { alert('Cannot inject dynamic contents into iframe.'); }

The problem is that some pages displaying well with method 1, some with method 2 and some with method 3, but any of them do not approach to all web pages. Please help