简体   繁体   中英

Select across multiple text elements via rectangular area JS

I don't want to use the device's native text selecting ability, rather I want to replace it with my own method. How can I select text across multiple elements based off of coordinate positions on the page?

Basically, I have the results of Touch clientX/clientYs to make a rectangular area and I want to select all the text contained in that area

I've tried using absolutely-positioned elements and creating a range with those elements as the bounding start and end but it did not work.

I found these two methods that can be used to construct a range that can be added to the window selection.

https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM