jquery dynamic iframe - !document.write and IE issues

江枫思渺然 提交于 2019-12-08 01:59:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!