CKEditor - 阻止用户粘贴图像
我想为我的用户提供一个有限的编辑器,使用出色的 CKEditor。
我试图阻止人们添加图像,因此我阻止了“源”视图并禁用了“粘贴”按钮(仅保留“粘贴为文本”按钮)。
但是,仍然可以粘贴图像(从网页复制)。 有没有办法防止这种情况发生?
谢谢。
I would like giving my users a limited editor, using the great CKEditor.
I was trying to prevent people from adding images, therefore I've blocked the "Source" view and disabled the "paste" button (leaving only the Paste as Text button).
However, it is still possible to paste images (copied from web page).
Is there a way to prevent that as well ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道已经有一段时间了,但如果其他人遇到同样的问题。
您应该使用如上所述的插件这里检查所有图像,如果用户尝试插入图像,则会警告他不允许使用“图像”。
请注意,该插件无法下载,因此我们可能必须创建自己的插件。它非常简单。我们只需将他的代码复制并粘贴到
plugin.js
文件中即可。另一个选项解释如下 (我相信这只适用于粘贴事件,当拖动图像时不会执行任何操作!)
I know its been a while but if anyone else comes across this same problem.
You should use a plugin as described here to check for all images and if user tries to insert an image, then he is alerted that "images" are not allowed.
Please note that the plugin is not available to download so we might have to create our own plugin. Its pretty simple. We just have to copy and paste his code in
plugin.js
file.Another option is explained here (which I believe only works on paste event doesn't do anything when image is dragged ! )
您可以使用 'paste' 事件,这样您可以删除任何您不喜欢的内容。当然,您还应该在保存之前在服务器上验证内容。
You can use the 'paste' event, that way you can remove anything that you don't like. And of course, you should also verify the content at the server before saving.
这很有用,我使用了Nis的解决方案。但问题是,如果您删除图像,粘贴事件就会丢失。我做了改变来防止这种情况发生。
that was useful, I used the solution of Nis. but the problem is that if you drop a image, the paste event is lost. I made a change to prevent this situation.
如果您也希望能够在
Source
视图中阻止这种情况,只需将此代码添加到您的插件中即可:If you want to be able to prevent this in the
Source
view as well, just add this code to your plugin: