问题
Why does this work in all browsers - except IE:
var $iframe = $("<iframe name=" + strFrameName +"/>");
var $doc = $iframe.contents();
$doc.find("head").append("<link type='text/css' rel='stylesheet' href='" + opt.loadCSS + "'>");
However, if I use a non jquery object with document.write, it works ok in IE?
var $iframe = $("<iframe name=" + strFrameName +"/>");
var doc = $iframe[0].contentWindow.document;
doc.write("<link type='text/css' rel='stylesheet' href='" + opt.loadCSS + "'>");
I reworked a plugin, and wanted to rewrite it so that it wouldn't use document.write
However, now the iframe is getting created, but the head/body remain empty in IE.
see fiddle of original version (document.write): http://jsfiddle.net/jasonday/Tx4Uv/
and fiddle of updated attempt to use .append
instead of .write
:
http://jsfiddle.net/jasonday/Tx4Uv/4/
回答1:
Fixed.
I added a setTimeout
of 2ms to allow the iframe to fully render (mainly for IE) before appending to head and body.
来源:https://stackoverflow.com/questions/13318143/jquery-dynamic-iframe-document-write-and-ie-issues