Reliable, cross-browser way to get the boundaries of choice?

I need the user to be able to select some text, press a button and make the server remember the next time.

I read the answers to questions and answers in detail, tried some libraries, but no luck: I have not found a reliable tool yet.

It doesn't matter how the selection boundaries are defined: it can be "nth textNode, mth char" or "nth char text" or "nth char html" or something else if it allows the server to identify points in the document; what is really important is that the choice of the same words of the same document should give the same result on chrome, safari, IE, firefox.

EDIT: I don’t need it to work everywhere on the Internet: only on one site where the structure of the document is fixed, and only the contents of one div (or the like) will change.

+3
source share
1 answer

Try my Rangy library and its Serializer module . I'm not sure that this is exactly what you want, because you mentioned a server that remembers the choice, while my suggestion uses cookies, and the serialized choice will differ in different browsers. However, this is true as described in the first paragraph.

, -, , HTML - DOM.

0

Source: https://habr.com/ru/post/1776925/


All Articles