ns_error_unexpected unexpected error in tinymce editor

Recently i face a very intresting problem with tinymce editor. when i load tinymce editor from ajax on my page i show an error on inspector ie "ns_error_unexpected" and it stoped loading of my tinymce editor. After doing alot's of googling finally i find out the sollution.

Problem Reason :
-------------------
Actually the problem is that when you remove the tinymce by using tinymce.remove() .Its showning "ns_error_unexpected" error.

Sollution :

-----------
By using try, catch you can pass away by this problem. You just need to be simply add a try catch code below before initiliazing editor code like below :

<script type="text/javascript">


try {
tinymce.remove();
} catch (e) {}

tinymce.init({
    selector: "textarea",
    setup: function (editor)
    {
        editor.on('change', function () {
        tinymce.triggerSave();
        });
    },
    plugins: [
    "advlist autolink lists link image charmap print preview anchor",
    "searchreplace visualblocks code fullscreen",
    "insertdatetime media table contextmenu paste "
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter  alignright alignjustify | bullist numlist outdent indent | link image"
});


</script>


Please don't forgot to leave a comment if you like this post.

Chears ... 
Happy coding :)

4 Comments

  1. Thank you! I've been fighting with this for a couple of hours now. You helped me a lot :)

    ReplyDelete
  2. After several hours searching this code was the solution. Thank you very much

    ReplyDelete
Previous Post Next Post