我正在为TinyMCE编写一个插件,但在检测iframe中的点击事件时遇到了问题。
从我的搜索中,我得出了这个结论:
正在加载iframe:
<iframe src='resource/file.php?mode=tinymce' id='filecontainer'></iframe>iframe中的HTML:
<input type=button id=choose_pics value='Choose'>jQuery:
//Detect click
$("#filecontainer").contents().find("#choose_pic").click(function(){
//do something
}); 我见过的其他帖子通常都有不同域名的问题(这篇文章没有)。但是,仍然没有检测到该事件。
这样的事情能做吗?
发布于 2012-12-09 05:26:39
我是这样解决这个问题的:
$('#filecontainer').load(function(){
var iframe = $('#filecontainer').contents();
iframe.find("#choose_pics").click(function(){
alert("test");
});
});发布于 2012-11-18 18:32:38
我不确定,但你可以直接用
$("#filecontainer #choose_pic").click(function() {
// do something here
});或者,您也可以在iframe中添加一个<script>标记(如果您有权访问其中的代码),然后在框架中使用window.parent.DoSomething(),其中包含代码
function DoSomething() {
// do something here
}在父级中。如果这些都不起作用,请尝试window.postMessage。Here is some info on that。
发布于 2016-03-30 18:43:41
我知道这很旧,但是您的代码中的ID不匹配,一个是choose_pic,一个是choose_pics
<input type=button id=choose_pics value='Choose'>
$("#filecontainer").contents().find("#choose_pic").click(function(){
//do something
}); https://stackoverflow.com/questions/13439303
复制相似问题