I have a page with formated text and a toolbar (images with click events) beside it. One of the tool-commands is meant to be "mark yellow". (The text has to be read only and is formated.)
I tried to use document.getSelection()
and window.getSelection()
, but they seem to be designed for input fields only.
The other problem is, that as I click the tool bar my selection gets lost.
How do I get the selected text without loosing the selection?
The clue was to use onmousedown=""
or jQuery: .mousedown()
function to avoid loosing the selection.
这是如何使用Javascript选择文本 。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.