jQuery jHTMLArea - How to Allow Only Certain HTML Tags?
문제
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;
}); });
해결책
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.
제휴하지 않습니다 StackOverflow