如何从我使用 jquery 放置 iframe 的网页中的 iframe div 获取点击事件?
最佳答案
使用jQuery contents与 iframe 内容交互。
var frame = $('<iframe />').appendTo('body'); // create the iframe and append it to the body
var frameBody = frame.contents().find('body'); // grab the body node
frameBody.append('<div />'); // add a div
frameBody.find('div'); // retrieve the div
如果您从 URL 加载 iframe,请确保遵守同源策略,并等待 iframe 加载:
frame.load(function(){
var frameBody = frame.contents().find('body');
frameBody.find('div').click(function(){
// here is the iframe div click callback
});
});
关于jquery - 使用jquery从iframe获取点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5902863/