Jquery and binding an event to an iframe

Posted by dbr on Stack Overflow See other posts from Stack Overflow or by dbr
Published on 2010-03-26T21:02:49Z Indexed on 2010/03/26 21:03 UTC
Read the original article Hit count: 276

Filed under:
|

**I'm currently using a jquery textselect plugin to fire alerts based on the selection text anywhere on the page and it works just fine doing something like:

$(document).ready(function() {
    $(document).bind('textselect', function(e) {
        alert(e.text); 
    });
});

I've since had to add an iframe to the page and I need the text selection to work on text within the iframe as well. I'm trying to do something like this but it's not working:

$(document).ready(function() {
    $('#iframeId').load(function() {
    $(document.getElementById("iframeId").contentWindow).bind('textselect',function(e) {
    alert(e.text); 
    });
});

At this point I've tried a whole mess of ways to reference the iframe document without any success. Any ideas?**

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript