使用live()在加载时获取iframe内容 [英] Get iframe contents on load using live()

查看:84
本文介绍了使用live()在加载时获取iframe内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用iframe的文件上传脚本,因此页面无需重新加载。

I've got a file upload script working with an iframe so the page doesn't have to reload.

我遇到了有关检索数据的问题当使用jQuery的 .live()事件加载时,来自 iframe,如下所示:

I've run into an issue concerning retrieving data from the iframe when it's loaded using jQuery's .live() event, like this:

$("iframe").live("load", function() {
    console.log($(this).contents().find("body").html());
});

此事件甚至没有触发(我在Firebug中什么都没得到),所以我怎么能去在从我的文件上传脚本加载一些内容后获取iframe的HTML?我想这样做,所以我可以在服务器上运行PHP脚本的返回状态。

This event doesn't even fire (I get nothing in Firebug), so how can I go about getting the HTML of an iframe after it's loaded some content from my file upload script? I want to do this so I can get the return state of the PHP script run on the server.

我必须使用 .live() 因为这些元素是动态添加的,这意味着传统的 .load()将无效。

I have to use .live() as these elements are dynamically added, meaning the traditional .load() won't work.

推荐答案

来自jQuery文档:

From jQuery documentation:

注意:.live()和.delegate()方法不能用于检测iframe的load事件。 load事件没有正确地冒泡父文档,而且事件授权不需要Firefox,IE9或Chrome设置event.target。

http://api.jquery.com/load-event/

您是否可以提供有关您尝试做的更多信息,应该可以捕获事件,但不能使用iFrame加载。

Can you provide a little more information on what you're trying to do, it should be possible to catch the event but not by using iFrame load.

这篇关于使用live()在加载时获取iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆