문제

In Firefox Extension development, I wants to get selected content from the chrome page, when I use content.getSelection(), its working fine .

But if the selected text is in the iframe, its not working. anyone can help me ?

도움이 되었습니까?

해결책

You need to call getSelection() on the window object where text has been selected. For example, if there is an <iframe id="iframe"> in the content document, you would use the following to get the selection in that frame:

alert(content.document.getElementById("iframe").contentWindow.getSelection());

If you don't know where the user selected text and you want to look at all frames then you should go through them recursively starting at the top level, something like this:

function getSelection(wnd)
{
  var result = wnd.getSelection();

  for (var i = 0; !result && i < wnd.frames.length; i++)
    result = getSelection(wnd.frames[i]);

  return result;
}

alert(getSelection(content));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top