Вопрос

I want to prevent writing html tags in nicEditor.

<div id="sample">
  <script  type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script> <script type="text/javascript">
//<![CDATA[
        bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
  //]]>
  </script>
  <textarea onblur="this.value = this.value.replace(/<\/?[^>]+>/gi, '')" name="process" style="width: 300px; height: 100px;" id="process">
         hello <b>world</b>
  </textarea>
</div>  

I have tried above regex..but it doesn't work.. I am using the same regex onblur="this.value = this.value.replace(/<\/?[^>]+>/gi, '')" for simple textbox.and it works fine.

I also want to know that, is it the proper way to prevent html tags from user inputs for security purpose?

Это было полезно?

Решение

Try to test the order of priority of the events. Attach two handlers form.submit and textarea.blur and e.preventDefault inside submit. And use inside both of them console.log('submit') and console.log('blur') to see which one fires before. Cause the problem may be in the submit which fires before blur

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top