我正在使用 CKEditor4 内联编辑我的页面内容。但是,当我将 Google AdSense 代码添加到内容的原始 HTML 并加载内联编辑器时,脚本会被执行,并且新的代码iframe
会被放置在我的 editable div
. 当我保存页面时,它会同时保存 iframe 和脚本;所以下次我启动内联编辑器时,它会创建另一个。
这真的很烦人,我想知道是否有人知道如何防止 CKEditor4<script>
在编辑器本身中执行标签。
我整天都在谷歌搜索解决方案,但找不到任何解决方案。
You can filter any kind of code both when it's parsed and returned. The easiest way, I guess, is removing the iframe
when editor data is being saved. Frankly, I'm not really into AdSense but I observed that generated code is an ins
tag wrapped in paragraph. You can eventually extend this filter to be more specific, if you want.
CKEDITOR.inline( 'editable', {
on: {
instanceReady: function() {
this.dataProcessor.htmlFilter.addRules( {
elements: {
p: function( element ) {
var children = element.children;
for ( var i = children.length; i--; ) {
if ( children[ i ].name == 'ins' )
return false;
}
}
}
} );
}
}
} );
Also read about dataProcessor
it's a powerful tool in CKEditor. You'll do magic once you got it.