+7 votes
Hi all, here's the situation:

There is a page with a pdf file uploaded to it via <embed> or <iframe> I can select text there, the pdf itself displays fine, but window.getSelection() doesn't work. I googled the issue and found out that it's impossible to do so, because in this way another page of another "window" is loaded via iframe or embed, maybe someone has encountered this, how can I get this selected text from the window with pdf?
Can't you download all the pdf on your hosting?
Maxim Kirshin I even checked it with events onmouseover and onmousemove, these events triggered only at the borders of iframe, and the pdf itself is loaded into embed element and it is unclear how to get access to it. In general, the task is a bit different, but my main goal is to get the selected text in some way.
igor_solweb ,
var idoc = iframe.contentDocument || iframe.contentWindow.document; // проверь iframe.contentWindow - вроде как это обращение к объекту window iframe'а
See an example here link
I output anything yet ))) because the way does not work through a frame, as written in the article on the link above, if the frame leads to the "same source", then you can control it, but if external, then no access. I have all the pdf are on a third-party hosting, and therefore different sources and displays an error.
Used the code:
var iframe = document.getElementById('my');
var idoc = iframe.contentDocument || iframe.contentWindow.document; // ie compatibility
var text = idoc.getSelection().toString();
What exactly do you output through js?

1 Answer

0 votes
Maybe something like this?