Question

Is this possible to limit the HTML only to Bold, Italic, Underline and Breaks in jHTMLArea plugin editor? I'm mostly interested in stripping P tags and using two breaks instead. What I have done in the mean time is:

$.fn.stripPTags = function(_str) {
    _str = _str.replace('<p></p>', '');
    _str = _str.replace('<p>', '');
    _str = _str.replace('</p>', '<br /><br/ >');
    return _str;
}

and:

$(document).ready(function(){
$('#txtDefaultHtmlArea_Save').click(function(){
    var _str = $.fn.stripPTags( $('#txtDefaultHtmlArea').htmlarea('toHtmlString') );
    return false;

}); });

Was it helpful?

Solution

The simplest would be to customize the toolbar by taking out the HTML button. You would just call the following code in the $(document).ready(function().

$("#txtCustomHtmlArea").htmlarea({
    toolbar: ["bold", "italic", "underline", "|", "link", "unlink"]
});

The user could enter HTML tags but the editor will sanitize any tags they enter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top