Range.deserializeSelection checksum error?

风格不统一 提交于 2019-12-25 03:00:31

问题


It's a followup question of this. I've serialized the selection of text in an iframe and want to restore it but it gives me an error, "Uncaught Error: deserializeRange: checksums of serialized range root node (XXXXX) and target root node (XXXXX) do not match"

var iframe = $("iframe")[0];
var selection = rangy.getSelection(iframe);
var serializeSelection = rangy.serializeSelection(selection);
alert(serializeSelection);
rangy.deserializeSelection(serializeSelection);

Demo: http://jsfiddle.net/codef0rmer/2d6Bk/1/


回答1:


You need to provide the window object as the third parameter:

rangy.deserializeSelection(serializeSelection, null, iframe.contentWindow);

Demo: http://jsfiddle.net/2d6Bk/2/

This is more awkward than it should be. Version 1.3 allows you to use iframe rather than iframe.contentWindow, but it's still too unreadable so I will improve this somehow.




回答2:


Regarding "Uncaught Error: deserializeRange: checksums of serialized range root node (XXXXX) and target root node (XXXXX) do not match" error:

Rangy serialization and de-serialization should be done to same format and type text. Sometimes the text or format or css may be changes while deserializing. So you have to take care of your text. As your using Iframe, call the methods once after your text has been loaded in the iframe. The mistake what we do is we serialize the text after page loads and while deserializing, we try to deserialize the text after iframe loading. Just check whether your iframe is loaded with content or not before you start deserializing.



来源:https://stackoverflow.com/questions/11586115/range-deserializeselection-checksum-error

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