Reputation: 9449
From the research I've done, it seems like Rangy is the best way to go for saving/restoring selections. I'm unable to get it to work, however.
I included the core and selectionsaverestore files.
I have a button that when clicks, fires the following:
savedSel = rangy.saveSelection();
console.log(savedSel);
The log returns:
Object
doc: HTMLDocument
rangeInfos: Array[1]
restored: false
win: DOMWindow
__proto__: Object
I do not see any marker elements in my contenteditable however, and when I try to restore, nothing happens. What am I doing wrong?
Upvotes: 1
Views: 1469
Reputation: 11
You need to import two files for it to work:
<script type="text/javascript" src="./rangy-1.2.3/rangy-core.js"></script>
<script type="text/javascript" src="./rangy-1.2.3/rangy-selectionsaverestore.js"></script>
Perhaps you only imported the "rangy-core.js" ?
Upvotes: 1