大家好,在发布这篇文章之前,我已经去过很多地方试图解决这个问题,但都没能解决。This是我遇到的最接近的东西。
我正在尝试动态创建iframe并将内容加载到其src中,然后使用回调对其执行某些操作。和往常一样,除了IE之外,一切都可以在FF/Chrome中运行。
我有这样的东西:
var iframe = $('#helloworld');
if (!iframe.exists()) {
iframe = $('<iframe/>', {
id : 'helloworld',
src : "about:blank"
}).css({
width : "100%",
height : "100%"
});
}..。
iframe.load(options.src, function() {
div.append(this);
$(this).find('body').append(box);
box.dialog({
close: function( event, ui ) {
iframe.load("about:blank");
div.hide();
}
});
});与许多其他人的问题类似,它在回调时失败了。从我在其他帖子中读到的,这是由于无效的html返回到iframe,然而,我已经检查过了,我的html是有效的。
这是我为我的iframe返回的内容,正如您所看到的,出于测试目的,它已经被剥离到最低限度。
<!DOCTYPE html>
<html dir="ltr">
<head>
<title>Testing</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<style type="text/css">
</style>
</head>
<body></body>
</html>在IE中,jQuery正在消亡,@ line 5951:
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
this.appendChild( elem );
}
});
},SCRIPT65535:对方法或属性访问的意外调用。jquery-1.9.1.js,第5951行5个字符
其中this应该是我的iframe,但它没有appendChild方法。
对我进一步解决这个问题有什么建议吗?
发布于 2013-11-23 01:06:53
你不能像那样在iframe中使用load()。如果您想知道内容何时在iframe中加载完毕,请使用onload事件并设置src属性。
iframe.on("load", function() {
//code here
});
iframe.attr("src", options.src);您将在内容加载时获得您的回调。
现在,要使用iframe中的内容,需要使用contents()
iframe.contents().find("body")...发布于 2013-11-23 00:50:00
据我所知,.load将超文本标记语言加载到指定的节点。
所以iframe.load(options.src, /* */);
将加载options.src的值作为iframe的HTML体。我怀疑你是不是想这样。
我认为你想要:
iframe.attr("src", options.src);
// or
iframe.attr("src", "about:blank");https://stackoverflow.com/questions/20150105
复制相似问题