jquery动态iframe - !document.write和IE问题 [英] jquery dynamic iframe - !document.write and IE issues
问题描述
为什么这适用于所有浏览器 - 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中可以正常工作吗? / p>
var $ iframe = $(< iframe name =+ strFrameName +/>);
var doc = $ iframe [0] .contentWindow.document;
doc.write(< link type ='text / css'rel ='stylesheet'href ='+ opt.loadCSS +'>);
我重写了一个插件,并想重写它以便它不会使用 document.write
但是,现在iframe已经创建了,但是IE中的头部/主体仍然是空的。
查看原始版本的小提琴(document.write):
http://jsfiddle.net/jasonday/Tx4Uv/
以及更新尝试使用 .append $ c的小提琴$ c>而不是
.write
:
http://jsfiddle.net/jasonday/Tx4Uv/4/
已修复。
我添加了一个2ms的 setTimeout
,以允许iframe在追加到head和body之前完全呈现(主要用于IE)。 / p>
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/
Fixed.
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屋!