I've got an iframe that I filled like this:
var usableUrl = unescape(url);
var iframe = $("<iframe id='pageContentDownloader' name='pageContentDownloader' style='display:block'></iframe>");
$("body").append(iframe);
iframe.load(usableUrl, null, ondocloaded);
iframe.css({ "width": $(window).width(), "height": $(window).height(), "border": "0px" });
Later on, I want to in-place replace all of the <p>s and <div>s with modified versions of themselves:
$("#pageContentDownloader").contents().find("p, div")
.each(function () {
var para = $(this).text();
var words = para.split(" ");
var aWords = new Array();
$.makeArray(words, aWords);
var newPara = makePara(aWords);
$(this).replaceWith(newPara);
});
But for some reason, the last command doesn't work. I can see that $(this)
is the original para inside the iframe (I can see its content and I know that it is the original unmodified version of the para), and newPara definitely contains the appropriately modified content.
The $(this).replaceWith()
seems not to be working properly. The comments about issues with replacing tags with text elements in the replaceWith API docs don't apply here, since the replacement is a <div> filled with <span>s.
Is this some weird <iframe>/Query 1.4+ issue? I've tested this on HTML5, XHTML with IE8 and Chrome 5 beta. All of them leave me an empty iframe.