Anze
Anze

Reputation: 119

Inserting HTML into CKeditor from popup window

I've created plugin that calls external popup window:

exec : function( editor )
{
    window.open('index.php?mod=xxxx','Name popup','width=900,height=600');
}

That part works nice. How to send data back to CKeditor? I would like to append some HTML on current position on opener instance of CKeditor with jquery.

I've tried this, but it is not working:

$('a#clickMe').click(function()
{ 
     window.opener.CKeditor.insertHtml('Bla bla bla');
});

Upvotes: 0

Views: 4298

Answers (3)

Saul Dobney
Saul Dobney

Reputation: 31

A way to do it without the GET variable - add a global variable to your javascript (eg in the config.js file)

var myEditorInstance;

Then in the plug-in

exec : function( editor )
{
    myEditorInstance=editor;
    window.open('index.php?mod=xxxx','Name popup','width=900,height=600');
}

You can then reach this from the popup window with

window.opener.myEditorInstance.insertHtml('Bla bla bla');

It also means if you have multiple editors on the page, the pop up relates to the instance that opened the window.

Upvotes: 0

Anze
Anze

Reputation: 119

Found a way to do it:

exec : function( editor )
{
    window.open('index.php?mod=xxxx&CKEditor='+CKEDITOR.currentInstance.name,'Name popup','width=900,height=600');
}

Then insert passed $_GET['CKEditor'] into element 'rel' attribute.

Html:

<a id="clickMe" rel="<?=$_GET['CKEditor']?>">click me</a>

jQuery:

 $('a#clickMe').click(function(){
        var editor = $(this).attr("rel");
        window.opener.CKEDITOR.instances[editor].insertHtml('bla bla');
 });

Upvotes: 2

Reinmar
Reinmar

Reputation: 22023

Try:

window.opener.CKEDITOR.instances.nameOfYourInstance.insertHtml( 'bla bla' );

However, I don't know if without focusing editor first it will always work. You should rather use CKEditor's dialog API.

Upvotes: 0

Related Questions