user3722851
user3722851

Reputation: 147

Javascript Ckeditor Get Mouse click position

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 ?

Upvotes: 0

Views: 844

Answers (2)

epascarello
epascarello

Reputation: 207511

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

Upvotes: 2

Ondipuli
Ondipuli

Reputation: 468

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");

Upvotes: 1

Related Questions