检测iframe内的点击事件 [英] Detect click event inside iframe

查看:141
本文介绍了检测iframe内的点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为TinyMCE编写插件,并在检测iframe中的点击事件时遇到问题。

I'm writing a plugin for TinyMCE and have a problem with detecting click events inside an iframe.

在我的搜索中,我想到了这一点:

From my search I've come up with this:

加载iframe:

<iframe src='resource/file.php?mode=tinymce' id='filecontainer'></iframe>

HTML iframe内:

HTML inside iframe:

<input type=button id=choose_pics value='Choose'>

jQuery:

//Detect click
$("#filecontainer").contents().find("#choose_pic").click(function(){
    //do something      
}); 

我见过的其他帖子通常对不同的域有问题(这没有)。但是,仍然没有检测到事件。

Other posts I've seen usually have a problem with different domains (this hasn't). But, still, the event isn't detected.

可以这样做吗?

推荐答案

通过这样做:

$('#filecontainer').load(function(){

        var iframe = $('#filecontainer').contents();

        iframe.find("#choose_pics").click(function(){
               alert("test");
        });
});

这篇关于检测iframe内的点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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