Restore multiple selections from db using Rangy

核能气质少年 提交于 2019-12-08 05:59:41

问题


What i want to do :

->Show a plain HTML page to a user ->User has the ability to highlight text on that page ->When user logs in next time , i should be able to retrieve and show his previous (multiple) highlight on the page.

What i have done :

I used the Library/API : Rangy.With this iam able to select the text and highlight it with the users preferred color.

The Problem :

I tried the serialize and de-serialize function , but when i try to deserialize (after page has been reloaded) it gives me an error saying

checksums of serialized range root node (ec0c8cf0) and target root node (d4997863) do not match

Everytime i reload the page , there is a new root node , how can i fix the deserialize in this case ?

Created a JS-Fiddle : demo / js-fiddle

What is this - If you check my demo , i select the first word of the description ie "Please " , i get the text highlighted , and i also get the serial as :

0/3/1/3/0/1/1/2:9,0/3/1/3/0/1/1/2:9{b3002d92}

so what i did is , i hard coded this serial and put it into the deserializeSelection funciton in the page onLoad function like this :-

rangy.deserializeSelection('0/3/1/3/0/1/1/2:9,0/3/1/3/0/1/1/2:9{b3002d92}');

so technically , it should highlight the "Please" in the description , whenever the page loads , irrespectively.But it does not , instead give me the above error in block. Can you help me solve this.please.Thank you

Extra:

1.I really do not understand the serialize and de-serialize methods of rangy.

2.My very abstract road map from here is to , do an AJAX call , on page load and fetch all (serialized) selection of the user for this page from my db and iterate over them and do a de-serialize.

Any help , would be really appreciated. Thank you.


回答1:


What I think is you should try this:

var selObj = rangy.getSelection();
var se = rangy.serializeSelection(selObj, true); //true to avoid DOM checksum


来源:https://stackoverflow.com/questions/14416524/restore-multiple-selections-from-db-using-rangy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!