I am writing a Chrome Extention where I need to store and restore the user’s highlighted selection. The stored information will be stored on my server. I am wondering how I would do this?
I looked into using Range, but am unsure if this is the right way since the example below only worked in FireFox.
I found this example but it only works in FireFox 🙁
I think the technique on that page probably does work in Chrome: there’s no reason why it shouldn’t. When I save the selection and reload, I see the selection restore and then quickly disappear, so I suspect something in the page (possibly the ads) is destroying the selection somehow.
If you can’t get that to work, you could try the serializer module of my Rangy library, although it’s probably overkill for just Chrome.
In general, using the browser’s
SelectionandRangeAPIs is definitely the way to go. They are now standardized and universally supported (with some quirks and bugs, naturally) in current browsers.