2017-09-22 4 views
1

CKEditor를 사용 중이고 CKEditor iframe 창에서 onClick 이벤트에 대한 작업을 수행하고 싶습니다. 즉 CKEditor의 편집 가능 영역입니다.CKEditor iframe에 onClick 이벤트를 추가하는 방법

CKEDITOR.instances['ckEditor'].on('contentDom', function() { 
     this.document.on('click', function(event){ 
      // calling some other function or some logic 
     }); 
    }); 

그러나 위의 코드는 처음 CKEditor iframe을 클릭했을 때만 작동했습니다. 왜 그렇게? html 페이지의 다른 요소를 클릭 한 다음 CKEditor iframe을 다시 클릭하면 더 이상 작동하지 않습니다.

답변

1

일부 기본 샘플에서는 아래 코드를 사용해 보시기 바랍니다. 기본적으로 이벤트를 편집기 editable에 첨부하고 contentDom 이벤트를 사용하는 경우 click의 이벤트 처리기는 소스 모드로 전환 한 후에도 실행해야하며 실제로 오래된 iframe이 삭제되어 완전히 새로운 인터페이스가 생성됩니다.

var editor = CKEDITOR.replace('editor1', {}); 
editor.on('pluginsLoaded', function(event) { 
    editor.on('contentDom', function(evt) { 
     editor.editable().attachListener(editor.editable(), 'click', function(e){ 
      console.log('click'); 
     }); 
    }); 
}); 
+0

스크립트가 완벽하게 작동합니다. CKEditor 값의 인스턴스로 편집기 값을 변경했습니다. – Dhiraj