Need to highlight and copy text from google doc viewer to clipboard

醉酒当歌 提交于 2019-12-12 05:24:57

问题


I have to create a process where a document is shown to the user and the user can highlight text and copy (and eventually paste) the text from some portions of the document.

I am using google doc viewer in an iframe (since I need a universal doc viewer that's free - although I'm open to other ideas on viewers). Google doc viewer does what I need but it seems that I don't have access to the internals of the iframe to get the highlighted contents.

I've looked at many links related to triggering a copy (cntl-c) in javascript, but nothing firm in the process.

Ideally I would like a button outside of the iframe to click on which would copy to the clipboard the selection a user made inside of the google doc viewer.

Any suggestion on how to achieve this?


回答1:


Utilising window.getSelection();.

tutorial: http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html



来源:https://stackoverflow.com/questions/15722712/need-to-highlight-and-copy-text-from-google-doc-viewer-to-clipboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!