CKEditor 4 or above
I have form > textarea with CKEditor enabled and functioning.
I have iframe in modal dialog and inside iframe is button with insert_media() javascript function.
function insert_media( element ) {
// get element html decode
element = htmlspecialchars_decode( element, 'ENT_QUOTES' );
// htmlspecialchars_decode is external function.
// CKEditor insert element ---------------------------------------------
// use .insertElement()
var CKEDITOR = window.parent.CKEDITOR;
var element = CKEDITOR.dom.element.createFromHtml(element);
// body_value is name of textarea
// this code only works with specific textarea NOT current active textarea
//CKEDITOR.instances.body_value.insertElement(element);
var current_instance_ckeditor = window.parent.test_current();
// CKEditor insert element ---------------------------------------------
// close modal dialog at parent window
window.parent.close_dialog();
// done
return false;
}// insert_media
and this is javascript in main page html
function close_dialog() {
$('#media-modal').modal('hide');
}// close_dialog
function test_current() {
console.log( CKEDITOR.currentInstance.name );
}
The problem is i cannot get current active CKEditor to insert element with insertElement command.
CKEDITOR.currentInstance is undefined or null
window.parent.CKEDITOR.currentInstance is undefined or null
How to get current active CKEditor from iframe?
file for test: http://www.megafileupload.com/en/file/420060/test-ckeditor-zip.html