检测 iframe 内的点击事件 [英] Detect click event inside iframe
本文介绍了检测 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>
iframe 中的 HTML:
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屋!
查看全文