views:

283

answers:

1

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;

}); });

+1  A: 

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.

Scott Gottreu
hmm, unfortunately for me, bolds and italics are required. Thx
Sam3k
The toolbar would allow the user to add bold, italic, underline, and anchor tags but it would add the tags on the back end where the user wouldn't see them. The user just wouldn't be able to manually enter a `<b>` or more malicious `<script>` in the editor.
Scott Gottreu
That makes perfect sense. Thanks Scott
Sam3k