【问题标题】:NicEdit Error in ChromeChrome 中的 NicEdit 错误
【发布时间】:2011-07-19 11:30:16
【问题描述】:

我在我的网站上使用 NicEdit WYSIWYG 插件。

我注意到在 Chrome 中实例化 NicEdit 时,会生成以下 Javascript 错误:

Uncaught TypeError: Object  has no method 'createRange'

这不会阻止插件工作,但如果可能的话,我想阻止这种情况。下面是冒犯的方法:

getRng : function() {
        var s = this.getSel();
        if(!s) { return null; }
        return (s.rangeCount > 0) ? s.getRangeAt(0) : s.createRange();
}

NicEdit 作为一个项目似乎已经死了,这就是为什么我在这里问这个问题而不是在 NicEdit 论坛上问这个问题。我希望有人知道这个问题的“快速修复”。在所有其他方面,NicEdit 对我来说都很好,所以我还不愿意切换到不同的 WYISWYG 插件......

感谢(提前)您的帮助。

【问题讨论】:

    标签: javascript google-chrome nicedit


    【解决方案1】:

    问题是Webkit的选择对象的实现没有定义createRange( )方法。那个方法好像是specific to Internet Explorer。对于 Webkit 和 Gecko DOM implementationscreateRange( ) 方法是在 document 对象上定义的。有了这些知识,getRng( ) 的修复就变成了:

    getRng : function() {
        var s = this.getSel();
        var rng;        
    
        if(!s) { return null; } 
        if (s.rangeCount > 0) {
            rng = s.getRangeAt(0);
        } else if ( typeof s.createRange === 'undefined' ) {
            rng = document.createRange();
        } else {
            rng = s.createRange(); 
        }       
        return rng;
     },
    

    我在为即将到来的项目评估大量富文本编辑器时遇到了这个问题,并且不得不使用 nicEdit 创建一个示例页面。

    【讨论】:

      【解决方案2】:

      相同的代码,用 nicEdit 当前设计编写:

      getRng : function() {
          var s = this.getSel();
          if(!s) { return null; }
          return (s.rangeCount > 0) ? s.getRangeAt(0) : (typeof s.createRange == 'undefined') ? document.createRange() : s.createRange();
      },
      

      【讨论】:

        【解决方案3】:

        【讨论】:

        • 谢谢!有人联系作者合并这些修复吗?
        猜你喜欢
        • 1970-01-01
        • 2012-06-13
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 2013-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多