Search code examples
javascriptjqueryiframerangy

grab selected text from multiple iframe using rangy?


This is a followup question. I've been trying to grab the selected text from multiple iframe using rangy. The code seems to be working for 1st iframe .

i want to grab elements using the same button., for div it works k. but in iframe we need to specify the iframe and when i tried the array of iframes ., that is not working


Solution

  • Use jQuery $.each:

    $(function () {
        $('button').click(function () {
            $.each(iframe, function(idx, vl) {
                var selection = rangy.getSelection(iframe[idx]);
                alert(selection);
            });
        });
    });
    

    Demo: http://jsfiddle.net/cWV3G/