Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting 'NS_ERROR_UNEXPECTED' while using tinymce in Mozilla

I am using tinymce in my application for a rich text box experience, I am getting this weird problem while using it in Mozilla. It works perfectly while using it first time, but if i load same tinymce instance second time it is giving below error in console screen.

NS_ERROR_UNEXPECTED

Please suggest the solution if any , Below is the code I am using:

 <script type="javascript">
    tinymce.remove();
    jQuery('#tinymce').tinymce({
        height: 250,
        width: 750,
        entity_encoding: "raw",
        encoding: "xml",
        force_br_newlines: false,
        force_p_newlines: false,
        forced_root_block: 'div',
        statusbar: false,
        theme: 'modern',
        menubar: false,
        plugins: "mention " + plugins,
        toolbar1: toolbar1,
        toolbar2: toolbar2
});
</script>
like image 987
kartik ghodasara Avatar asked Jun 16 '26 02:06

kartik ghodasara


1 Answers

To get rid of this problem simply wrap tinymce.remove() in try catch.

    try {
        tinymce.remove("#id");
    } catch (e) {}

The cause of this problem is that while the editor does not exist in DOM, tinyMCE script thinks it's still out there. You can check it by placing a breakpoint on tinymce.remove() and running tinymce.editors.length - it will return a positive value even if the editor is not there. For some unknown reason the problem appears only in Firefox.

like image 87
Pramus Avatar answered Jun 18 '26 00:06

Pramus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!