我想为我的用户提供一个有限的编辑器,使用出色的 CKEditor。
我试图阻止人们添加图像,因此我阻止了“源”视图并禁用了“粘贴”按钮(仅保留“粘贴为文本”按钮)。
但是,仍然可以粘贴图像(从网页复制)。
有没有办法防止这种情况发生?
Thanks.
我知道已经有一段时间了,但如果其他人遇到同样的问题。
你应该使用此处描述的插件 http://www.isummation.com/blog/block-drag-drop-image-or-direct-image-paste-into-ckeditor-using-firefox/检查所有图像,如果用户尝试插入图像,则会警告他不允许“图像”。
请注意,该插件无法下载,因此我们可能必须创建自己的插件。它非常简单。我们只需将他的代码复制并粘贴到plugin.js
file.
CKEDITOR.plugins.add( 'blockimagepaste',
{
init : function( editor )
{
function replaceImgText(html) {
var ret = html.replace( /<img[^>]*src="data:image\/(bmp|dds|gif|jpg|jpeg|png|psd|pspimage|tga|thm|tif|tiff|yuv|ai|eps|ps|svg);base64,.*?"[^>]*>/gi, function( img ){
alert("Direct image paste is not allowed.");
return '';
});
return ret;
}
function chkImg() {
// don't execute code if the editor is readOnly
if (editor.readOnly)
return;
setTimeout( function() {
editor.document.$.body.innerHTML = replaceImgText(editor.document.$.body.innerHTML);
},100);
}
editor.on( 'contentDom', function() {
// For Firefox
editor.document.on('drop', chkImg);
// For IE
editor.document.getBody().on('drop', chkImg);
});
editor.on( 'paste', function(e) {
var html = e.data.dataValue;
if (!html)
return;
e.data.dataValue = replaceImgText(html);
});
} //Init
} );
另外一个选择在这里解释 http://drupalwise.wordpress.com/2013/06/12/how-to-prevent-pasting-images-in-ckeditor-through-firefox/(我相信这只适用于粘贴事件,当拖动图像时不会执行任何操作!)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)