Old question but the answer might be useful because TinyMCE is still used nowadays.
The problem is that when you set an HTML content to TinyMCE editor, the original content is actually modified. For example HTML properties might be inverted. It doesn't change anything for the rendering result but a string comparison doesn't work.
So what I did is simply put the original HTML in an invisible TinyMCE editor and then perform the comparison between this one and my "real" editor.
<script type="text/javascript">
tinymce.init({
selector: 'textarea#originalContent'
});
</script>
<textarea id="originalContent" style="display:none;"></textarea
And then you trigger the comparison whenever you need. In this example I chose to perform it every time my real TinyMCE editor's content is modified
<script type="text/javascript">
tinymce.init({
theme: 'modern',
height: 500,
width: 950,
selector: 'textarea#tinymcePopup',
setup: function (ed) {
ed.on("change", function () {
contentChanged(ed);
})
}
});
function contentChanged() {
var originalContent = tinymce.get('originalContent').getContent();
var editableContent = tinymce.get('tinymcePopup').getContent();
if (originalContent != editableContent) {
console.log('changed');
}
else {
console.log('not changed');
}
}
</script>
<textarea id="tinymcePopup"></textarea>
` so it appears changed using your solution even though the rendered HTML is not changed.
– user1032531 Oct 03 '13 at 12:17