从代码视图切换到编辑器的Summernote事件

我使用google caja html sanitizer来阻止客户端的脚本执行。 所以我需要将事件从代码视图切换到编辑器,在那种情况下我会清理html。 由于该开关没有任何事件,我写了这样的东西:

$('#newFeaturesView .note-editor .btn-codeview').click(function () { if (!$(element).hasClass('active')) { var html = $('#summernote').summernote('code'); var sanitizedHtml = html_sanitize(html, urlTransformer, classIdTransformer); $('#summernote').summernote('code', sanitizedHtml); } }); 

但是如果html是脏的并且包含例如带有警报的脚本,则在清除html并将其粘贴到html编辑器之前执行警报。 如何强制我的清洁function先触发?