CKEditor + IE7+8“null 或不是对象”错误

发布于 2024-09-15 04:51:11 字数 1221 浏览 6 评论 0原文

我的问题是我使用 CKEditor 3.4 jQuery 插件,在编辑器上执行 $(selector).val(html) 调用时,它在 IE 7+8 中给我一个错误:

错误: 'this.$.innerHTML' 为 null 或不是对象

...在调试器中运行时,指向巨大的 CKEditor.js 中的这行代码:

getHtml:function(){var i=this.$.innerHTML;return c?i.replace(/<\?[^>]*>/g,''):i;}

...在源代码中转换为:

getHtml : function()
{
    var retval = this.$.innerHTML;
    // Strip <?xml:namespace> tags in IE. (#3341).
    return CKEDITOR.env.ie ? retval.replace( /<\?[^>]*>/g, '' ) : retval;
},

我的违规代码(精简,但仍然给出错误):

var editor_data = $("textarea#body").val();
$("textarea#body").val(editor_data);

...以及后代的文本区域代码:

<textarea name="body" rows="15" cols="50" class="wysiwyg" id="body"></textarea>

我尝试在 IE8 中的 jsFiddle 中复制,但奇怪的是它按预期工作。我也很想提供一个工作示例,但不幸的是,由于我无法控制的原因,我无法提供。

我也尝试过这个修复,它解决了错误问题,但之后 setData 没有按预期工作,只是覆盖了编辑器内容。我承认这个问题+修复有点超出我的能力...: http://dev.ckeditor .com/ticket/4566

(抱歉,帖子很长:S)我也尝试在 CKEditor 中使用直接 JavaScript API(放弃 jQuery 集成),但它抛出了相同的错误。

有人希望我尝试解决这个问题,或者对它可能是什么有任何预感吗?我们将不胜感激!

My problem is that I'm using the CKEditor 3.4 plugin for jQuery, and it's giving me an error in IE 7+8 when executing a $(selector).val(html) call on the editor:

The error:
'this.$.innerHTML' is null or not an object

...which when run in the debugger, points to this line of code in the huge CKEditor.js:

getHtml:function(){var i=this.$.innerHTML;return c?i.replace(/<\?[^>]*>/g,''):i;}

...which translates to this in the source:

getHtml : function()
{
    var retval = this.$.innerHTML;
    // Strip <?xml:namespace> tags in IE. (#3341).
    return CKEDITOR.env.ie ? retval.replace( /<\?[^>]*>/g, '' ) : retval;
},

My offending code (stripped down, but still giving the error):

var editor_data = $("textarea#body").val();
$("textarea#body").val(editor_data);

... and the textarea code for posterity:

<textarea name="body" rows="15" cols="50" class="wysiwyg" id="body"></textarea>

I've tried reproducing in jsFiddle in IE8, but the strange thing is that it works as intended there. I'd love to also provide a working sample but I unfortunately cannot for reasons outside my control.

I've also tried this fix, and it cleared up the error issue, but after that setData did not work as intended and just overwrote the editor contents with nothing. I'll admit this problem+fix is a bit over my head...: http://dev.ckeditor.com/ticket/4566

(Sorry, long post :S) I've also tried to use the direct JavaScript API into CKEditor (abandoning the jQuery integration) and it threw the same error.

Anyone have anything they'd like me to try to fix this issue, or have any hunches of what it might be? It would be much appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏雪无痕 2024-09-22 04:51:11

就我个人而言,我不喜欢包含修改源代码的现有答案,因为一旦您更新 ckEditor,您就必须记住再次修改源代码。我遇到了与原始海报相同的问题,并找到了一个被认为是黑客但完全可用的修复程序。简单地说,Try/Catch 让 IE8 中的一切变得美好而快乐。现在在IE7下进行测试。此修复的另一个好处是,当失败时,您不会留下空白数据,而是可以获得尝试检索的实际内容。

var editor = $('textarea.editor').ckeditorGet();
var vPageContent = "";
try{
    vPageContent = editor.getData();//function call fails here
} catch(err){
    vPageContent = editor.getData();//but will work here
}

Personally I'm not a fan of the existing answer that consists of modifying the source code because as soon as you update ckEditor, then you have to remember to modify the source yet again. I was having the same problem as the original poster and found a fix that is considered a hack, but totally usable. Simply, a Try/Catch made it all nice and happy in IE8. Now to test in IE7. The other bonus of this fix is that you're not left with blank data when it fails but that you get actual content you were trying to retrieve.

var editor = $('textarea.editor').ckeditorGet();
var vPageContent = "";
try{
    vPageContent = editor.getData();//function call fails here
} catch(err){
    vPageContent = editor.getData();//but will work here
}
猫瑾少女 2024-09-22 04:51:11

可能不是最好的解决方案,但看看这个:
http://dev.ckeditor.com/ticket/4566

它声称替换为

getHtml:function(){var i=this.$.innerHTML;return c?i.replace(/<\?[^>]*>/g,''):i;},

getHtml:function(){return (this.$) ? this.$.innerHTML : "";},

解决问题。

我并不是说这是正确的答案,但我今天遇到了同样的问题,并且(目前)它似乎有效。

May not be the best solution but take a look at this:
http://dev.ckeditor.com/ticket/4566

It claims that replacing

getHtml:function(){var i=this.$.innerHTML;return c?i.replace(/<\?[^>]*>/g,''):i;},

with

getHtml:function(){return (this.$) ? this.$.innerHTML : "";},

will solve the problem.

I'm not claiming this is the correct answer but I had the same problem today and (for now) it seems to work.

半世晨晓 2024-09-22 04:51:11

小心多余的逗号。 IE 不喜欢多余的逗号。您可以使用 json lint 检查代码中是否有多余的逗号

be careful with extra comma. IE does not like exra commas. You can check your code for extra comma with json lint

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文