Javascript Ckeditor Get Mouse click position

荒凉一梦 提交于 2019-12-12 04:55:46

问题


I am using Ckeditor

View:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="~/Content/ckeditor/ckeditor.js"></script>


<input id="insertPattern" type="button" value="insert pattern" />

@Html.TextArea("editor", new { @class = "ckeditor", id = "aboutme" })

Javascript:

$(function () {

$('input#insertPattern').click(function () {

var txtarea = document.getElementById("aboutme");
var selection = txtarea.getSelection().getStartElement().getOuterHtml();

alert(selection);


}});

If i click to buton , i can not alert selection number of mouse click in Html.TextArea in Ckeditor.

Error:

In this part of javascript code

var selection = txtarea.getSelection().getStartElement().getOuterHtml();

I get below error,

uncaught typeerror undefined is not a function

Where i miss ? How can i get selection of mouse click ?


回答1:


Ultimately you want to insert text where exactly the mouse points right. This piece of code do that.

CKEDITOR.instances['aboutme'].insertText("insert some text into this string");



回答2:


You are not working with the editor

CKEDITOR.instances["editorID"].getSelection().getStartElement().getOuterHtml();

From your comments, you want to use

http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml



来源:https://stackoverflow.com/questions/24510628/javascript-ckeditor-get-mouse-click-position

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