“Error executing the insertHtml command” message in cleditor when inserting html in “View Source” mode

感情迁移 提交于 2019-12-11 04:03:43

问题


I've searched for the solution for this everywhere and have not found an answer, so you're my last hope, Stackoverflow...

With regard to cleditor, does anybody know how to make the "inserthtml" command in "View Source" mode work?

Currently, I have a method attached to a button's onclick handler that inserts a string into the cleditor's textarea:

editor.focus();
setTimeout(function() { editor.execCommand('inserthtml', stringToInsert); }, 0);

The above works fine in the normal Rich Text mode but if you try to execute it while in View Source mode, the following will happen:

  • In Firefox, it pops up a little message that says "Error executing the inserthtml command."
  • In Chrome, it fails silently
  • In IE:
    • If the textarea was empty, I hit a breakpoint in Visual Studio at "y(a).pasteHTML(c)" in what looks like jquery.cleditor.min.js, with the following message, "Microsoft JScript runtime error: Unspecified error."
    • If the textarea already contained text, I hit a breakpoint at "a.range[0].select()" in the same file with the following message, "Microsoft JScript runtime error: Could not complete the operation due to error 800a025e."

回答1:


hi i think it is very simmilar problem as here

i assume that code pasted by you is executed in button click function at the end of this function just add

return false;

add sopmething like that:

function someClick(e, data) {

    // Get the editor
    var editor = data.editor;

   editor.focus();
   setTimeout(function() { editor.execCommand('inserthtml', stringToInsert); }, 0);

   return false;

}

edit:

yep you are right it is not so easy : when yo are in normal mode your text area is actualy iframe when you are in source mode your textarea is again becomeing textarea so to edit data inside you can get it by

$('#mytextarea').val()

if you want to append something at the end you can use :

setTimeout(function() {$('#mytextarea').val($('#mytextarea').val()+'aaaaa') }, 3000);    

if you want to insert at current ursor cosition this should help : Cursor position in a textarea (character index, not x/y coordinates)



来源:https://stackoverflow.com/questions/9223467/error-executing-the-inserthtml-command-message-in-cleditor-when-inserting-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!