How To Handle Wysihtml5`s Br And Nbsp?
I'm using wysihtml5 editor and having some problems with the output. When I hit return I get a line break which is OK, but the tag isn't valid XHTML. It uses instead of
Solution 1:
The following codes provide text content(without html tags) and html content(with html tags). Who wants which of them;
textContent = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.textContent;htmlContent = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.innerHTML;
And my advice is that you shouldn't use jQuery for reaching the object when you listen events like keydown
, keyup
and keypress
. It doesn't work properly.
The below codes work perfect for me;
$('.wysihtml5-sandbox').contents().find('body').on("keyup",function() {
var content = document.getElementsByClassName('wysihtml5-sandbox')[0].contentWindow.document.body.textContent;
var contentLength = content.length;
var remaining = 2500-contentLength;
$("#characterCount").text(remaining);
});
Post a Comment for "How To Handle Wysihtml5`s Br And Nbsp?"