我想使用优秀的CKEditor为我的用户提供一个有限的编辑器.
我试图阻止人们添加图像,因此我阻止了"源"视图并禁用了"粘贴"按钮(仅保留"粘贴为文本"按钮).
但是,仍然可以粘贴图像(从网页复制).有没有办法防止这种情况发生?
谢谢.
我知道它已经有一段时间但是如果有其他人遇到同样的问题.
您应该使用此处所述的插件来检查所有图像,如果用户尝试插入图像,则会提示他不允许"图像".
请注意,该插件无法下载,因此我们可能需要创建自己的插件.它非常简单.我们只需将其代码复制并粘贴到plugin.js文件中即可.
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
} );
Run Code Online (Sandbox Code Playgroud)
这里解释了另一个选项(我认为只有在粘贴事件时才会对拖动图像做任何事情!)
| 归档时间: |
|
| 查看次数: |
5412 次 |
| 最近记录: |