【问题标题】:Getting 'NS_ERROR_UNEXPECTED' while using tinymce in Mozilla在 Mozilla 中使用 tinymce 时获取“NS_ERROR_UNEXPECTED”
【发布时间】:2015-10-22 10:26:32
【问题描述】:

我在我的应用程序中使用 tinymce 来获得丰富的文本框体验,在 Mozilla 中使用它时遇到了这个奇怪的问题。 它在第一次使用时运行良好,但如果我第二次加载相同的 tinymce 实例,它会在控制台屏幕中出现以下错误。

NS_ERROR_UNEXPECTED

如果有的话,请提出解决方案,下面是我正在使用的代码:

 <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>

【问题讨论】:

    标签: jquery firefox tinymce


    【解决方案1】:

    要摆脱这个问题,只需将tinymce.remove() 包装在try catch 中。

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

    这个问题的原因是虽然编辑器在 DOM 中不存在,但 tinyMCE 脚本认为它仍然存在。您可以通过在tinymce.remove() 上放置断点并运行tinymce.editors.length 来检查它 - 即使编辑器不存在,它也会返回一个正值。由于某些未知原因,该问题仅出现在 Firefox 中。

    【讨论】:

      【解决方案2】:

      这个错误很烦人。这与比赛条件有关。 尝试在重新启动编辑器之前将删除命令放在 setTimeout-Block 中,它应该可以工作。

      setTimeout(function(){
          var ed = tinymce.get('your_editor_id');
          if (ed) ed.remove();
      }, 1);
      

      更新:然后尝试不同的东西:

      var ed = tinymce.get('your_editor_id');
      if (ed) ed.remove();
      
      setTimeout(function(){
        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
         });
      }, 1);
      

      【讨论】:

      • 嗨 Thariama,谢谢您的意见,我已经尝试过您的解决方案,但是如果我将删除命令置于超时状态,那么它在第一次尝试时停止工作,因为在 init 命令之后执行删除命令,希望你在抓我!!
      • 然后尝试不同的方法,确保使用正确的编辑器 ID
      • 嗨 Thariama,是的,编辑器 ID 是正确的,我也尝试了您更新的解决方案,但是在执行删除命令时会出现此问题,我的意思是在 'ed.remove()' 所在的行在第二次打开 tinymce 时执行。
      • 如果延长超时时间会发生什么?
      • 没关系,因为在执行删除命令的地方会抛出异常。希望你能得到我!
      【解决方案3】:
      while (tinymce.editors.length > 0) {
          try {
              tinymce.remove(tinymce.editors[0]);
          } catch (e) {
              // alert(e);
          }
      }
      

      试试上面的代码。它应该可以正常工作。

      【讨论】:

        【解决方案4】:

        在我的情况下,所有建议都不起作用。

        我使用此代码解决了我的 Firefox 和 NS_ERROR_UNEXPECTED 问题:

        if( typeof window.tinymce != 'undefined' && $(window.tinymce.editors).length > 0 ){
          $(window.tinymce.editors).each(function(idx) {
            try {
            tinymce.remove(idx);
            } catch (e) {}
          });
        }

        希望这对某人有所帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多