2015-10-18 39 views
0

短篇小说:如何从JavaScript模拟在CKEditor的DEL按键

// get the editor instance 
var editor = CKEDITOR.instances.editor1; 

// this is what I want, but it does not exist 
editor.execCommand('delete'); 

// I've played with this, found somewhere, but without success. 
editor.fire('key', { keyCode : 46 }) 

长的故事:

有利用.NET WindowsForms WebBrowser控件中的CKEditor当问题。几个键,包括DELete键根本不会传播到控件。

我设法拦截使用全局键盘钩子的密钥,并将窗口消息直接发送到嵌入式IE窗口句柄,但没有成功。

现在我的目标是模拟JavaScript中的删除键,因为我可以从我的.NET应用程序调用js函数。 不知何故,这必须工作,因为它在虚拟键盘插件内工作。 (请参阅sample

很遗憾,我无法从插件代码得知它是如何工作的。 如果有人可以发布工作示例,我会很高兴。

谢谢!

回答

0

我在JavaScript虚拟键盘中找到了一个库(Jsvk plugin)。
它被称为DocumentSelection,可以找到here

<script src="./documentselection.js"></script> 

function simulateDelete() 
{ 
    var editor = CKEDITOR.instances.editor1; 
    var container = (editor.container.getElementsByTag('textarea').getItem(0) || 
        editor.container.getElementsByTag('iframe').getItem(0) 
        ).$; 
    DocumentSelection.deleteAtCursor(container, true); 
} 

也许有人已经无需外部libaray的简单的解决方案。

0

我觉得你想要一些线索......

在那里,它是...查看文档

Key Event in CKEditor

alert(event.getKey()); 

拿到关键因素,也是另一种是

alert(event.getKeystroke() == 65);// "a" key 
alert(event.getKeystroke() == CKEDITOR.CTRL + 65);// CTRL + "a" key 
alert(event.getKeystroke() == CKEDITOR.CTRL + CKEDITOR.SHIFT + 65);//CTRL + SHIFT + "a" key