Phi*_*p G 47 html javascript iframe jquery tinymce
我正在为TinyMCE编写一个插件,并且在检测iframe中的点击事件时遇到问题.
从我的搜索中我得出了这个:
正在加载iframe:
<iframe src='resource/file.php?mode=tinymce' id='filecontainer'></iframe>
Run Code Online (Sandbox Code Playgroud)
iframe中的HTML:
<input type=button id=choose_pics value='Choose'>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
//Detect click
$("#filecontainer").contents().find("#choose_pic").click(function(){
//do something
});
Run Code Online (Sandbox Code Playgroud)
我见过的其他帖子通常有不同域名的问题(这没有).但是,仍然没有发现事件.
可以这样做吗?
Phi*_*p G 59
我通过这样做解决了它:
$('#filecontainer').load(function(){
var iframe = $('#filecontainer').contents();
iframe.find("#choose_pics").click(function(){
alert("test");
});
});
Run Code Online (Sandbox Code Playgroud)
我不确定,但你可以使用
$("#filecontainer #choose_pic").click(function() {
// do something here
});
Run Code Online (Sandbox Code Playgroud)
或者你可以只<script>在iframe中添加一个标签(如果你有权访问里面的代码),然后window.parent.DoSomething()在框架中使用代码
function DoSomething() {
// do something here
}
Run Code Online (Sandbox Code Playgroud)
在父母.如果这些都不起作用,试试吧window.postMessage.这是一些信息.
小智 5
$("#iframe-id").load( function() {
$("#iframe-id").contents().on("click", ".child-node", function() {
//do something
});
});
Run Code Online (Sandbox Code Playgroud)