-1

Right now i get the selected text with window.getSelection().toString(). But unfortunately this doesn't work for text in iFrames. It's for a chrome extension, so i don't need to hear about how iFrames suck ;).

Nicky Smits
  • 2,980
  • 4
  • 20
  • 27
  • Does the way it is handled for a firefox extension work? http://stackoverflow.com/questions/10990690/content-getselection-is-not-working-when-selected-text-is-in-iframe – Darin Mar 20 '14 at 04:14

1 Answers1

0

If you have a reference to the iframe in question then

iframeEl.contentWindow.getSelection().toString();

... will do the job. If you want to get the selected text from all iframes, you could use window.frames, which is a collection of Window objects rather than frame/iframe elements:

var selectedTexts = [];
Array.prototype.forEach.call(window.frames, function(frameWin) {
    selectedTexts.push( frameWin.getSelection().toString() );
});
Tim Down
  • 318,141
  • 75
  • 454
  • 536