admin管理员组文章数量:1023065
I am trying to intercept links clicked on a page including those inside an iframe. This is the code that I have but it is not working. Any ideas what I need to do?
$("#container").delegate('a', 'click', function(e){
//do stuff
}
Container is the id of the div just inside the iframe.
Thanks in advance for any advice
I am trying to intercept links clicked on a page including those inside an iframe. This is the code that I have but it is not working. Any ideas what I need to do?
$("#container").delegate('a', 'click', function(e){
//do stuff
}
Container is the id of the div just inside the iframe.
Thanks in advance for any advice
Share Improve this question edited Jul 24, 2010 at 23:16 Nick Craver 631k138 gold badges1.3k silver badges1.2k bronze badges asked Apr 29, 2010 at 11:32 KaskadeKaskade 7954 gold badges14 silver badges21 bronze badges2 Answers
Reset to default 2You need to reach inside the <iframe>
and set the delegate there, you can do it like this:
$('#myiframe').contents().find("#container").delegate('a', 'click', function(e){
//do stuff
}
Edit - Mailslut makes a good points below, if the iframe isn't on the same domain (and port), you can't do anything like this. If that's the case and you want to know more about why, read about the same-origin policy there for security reasons.
Why not add the event listener inside the iframe and then call the parent / opener to notify the event.
If you the contents of the iframe is on a different domain, you won't be able to perform this as it is classed as "click-jacking", which was a big security threat.
I am trying to intercept links clicked on a page including those inside an iframe. This is the code that I have but it is not working. Any ideas what I need to do?
$("#container").delegate('a', 'click', function(e){
//do stuff
}
Container is the id of the div just inside the iframe.
Thanks in advance for any advice
I am trying to intercept links clicked on a page including those inside an iframe. This is the code that I have but it is not working. Any ideas what I need to do?
$("#container").delegate('a', 'click', function(e){
//do stuff
}
Container is the id of the div just inside the iframe.
Thanks in advance for any advice
Share Improve this question edited Jul 24, 2010 at 23:16 Nick Craver 631k138 gold badges1.3k silver badges1.2k bronze badges asked Apr 29, 2010 at 11:32 KaskadeKaskade 7954 gold badges14 silver badges21 bronze badges2 Answers
Reset to default 2You need to reach inside the <iframe>
and set the delegate there, you can do it like this:
$('#myiframe').contents().find("#container").delegate('a', 'click', function(e){
//do stuff
}
Edit - Mailslut makes a good points below, if the iframe isn't on the same domain (and port), you can't do anything like this. If that's the case and you want to know more about why, read about the same-origin policy there for security reasons.
Why not add the event listener inside the iframe and then call the parent / opener to notify the event.
If you the contents of the iframe is on a different domain, you won't be able to perform this as it is classed as "click-jacking", which was a big security threat.
本文标签: javascriptJqueryintercept links clicked inside an iframeStack Overflow
版权声明:本文标题:javascript - Jquery - intercept links clicked inside an iframe - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745592981a2157995.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论