jquery 动态 iframe - !document.write 和 IE 问题 [英] jquery dynamic iframe - !document.write and IE issues
问题描述
为什么这适用于所有浏览器 - 除了 IE:
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 + "'>");
但是,如果我在 document.write 中使用非 jquery 对象,它在 IE 中可以正常工作吗?
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 + "'>");
我重新编写了一个插件,并想重写它以便它不会使用 document.write
I reworked a plugin, and wanted to rewrite it so that it wouldn't use document.write
然而,现在 iframe 正在创建,但头部/主体在 IE 中仍然是空的.
However, now the iframe is getting created, but the head/body remain empty in IE.
查看原始版本的小提琴(document.write):http://jsfiddle.net/jasonday/Tx4Uv/
see fiddle of original version (document.write): http://jsfiddle.net/jasonday/Tx4Uv/
和尝试使用 .append
而不是 .write
的更新尝试:http://jsfiddle.net/jasonday/Tx4Uv/4/
and fiddle of updated attempt to use .append
instead of .write
:
http://jsfiddle.net/jasonday/Tx4Uv/4/
推荐答案
已修复.
我添加了一个 2ms 的 setTimeout
以允许 iframe 在附加到 head 和 body 之前完全呈现(主要用于 IE).
I added a setTimeout
of 2ms to allow the iframe to fully render (mainly for IE) before appending to head and body.
这篇关于jquery 动态 iframe - !document.write 和 IE 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!