Thanks to @JoseM's comment, the answer is uber-simple:
var bm = tinyMCE.activeEditor.selection.getBookmark();
$('#myTextBoxId').val(JSON.stringify(bm));
Question
I have a situation where I need to save the contents of the TinyMCE editor to a database, then retrieve them later with the caret/cursor position restored.
I see in the TinyMCE documentation that it might be possible using getBookmark()
, for example:
var bm = tinyMCE.activeEditor.selection.getBookmark();
However, I cannot work out how to serialize the value returned by getBookmark()
If I save it to a text box like this:
$('#myTextBoxId').val(bm);
the value just shows as [Object] [Object]
.
Is it even possible to save the bookmark across page postbacks?
Solution
Thanks to @JoseM's comment, the answer is uber-simple:
var bm = tinyMCE.activeEditor.selection.getBookmark();
$('#myTextBoxId').val(JSON.stringify(bm));