Range.deserializeSelection校验和错误? [英] Range.deserializeSelection checksum error?
问题描述
这是此的后续问题.我已经序列化了iframe中的文本选择并想要恢复它,但是它给了我一个错误,未捕获的错误:deserializeRange:序列化范围根节点(XXXXX)和目标根节点(XXXXX)的校验和不匹配"
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);
演示: http://jsfiddle.net/codef0rmer/2d6Bk/1/
推荐答案
您需要提供window对象作为第三个参数:
You need to provide the window object as the third parameter:
rangy.deserializeSelection(serializeSelection, null, iframe.contentWindow);
演示: http://jsfiddle.net/2d6Bk/2/
这比应该的要尴尬. 1.3版允许您使用iframe
而不是iframe.contentWindow
,但是它仍然太不可读,因此我将以某种方式进行改进.
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.
这篇关于Range.deserializeSelection校验和错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!