使用在线ckeditor http://sdk.ckeditor.com/samples/classic.html 我看到过去的选项(粘贴,粘贴为纯文本和从文字粘贴)不会从剪贴板复制。 我提供错误' 您的浏览器不允许您以这种方式粘贴纯文本。按Ctrl + Shift + V粘贴 。'但它似乎适用于IE(它提示允许访问)而不是Chrome或Firefox。
这是一个错误还是某些配置需要从浏览器或ckEditor完成。因为我记得几个月前我使用了相同的行为,它曾经用弹出窗口将你的内容粘贴到编辑器中。
谢谢, Vijai
答案 0 :(得分:5)
只需将此代码添加到config.js:
CKEDITOR.on("instanceReady", function(event) {
event.editor.on("beforeCommandExec", function(event) {
// Show the paste dialog for the paste buttons and right-click paste
if (event.data.name == "paste") {
event.editor._.forcePasteDialog = true;
}
// Don't show the paste dialog for Ctrl+Shift+V
if (event.data.name == "pastetext" && event.data.commandData.from == "keystrokeHandler") {
event.cancel();
}
})
});
答案 1 :(得分:1)
Chrome不允许这样做,因为这是一个安全漏洞。有人可能会盗取您复制的数据,因此Chrome和大多数其他浏览器都不允许您这样做。按ctrl shift和v粘贴它。
答案 2 :(得分:0)
据官方ckeditor团队说:目前没有解决此问题的方法。 请参阅此链接: https://github.com/ckeditor/ckeditor-dev/issues/469
我认为目前最好的解决方案是使用以下方法删除它们:
removeButtons : "Paste,PasteText,PasteFromWord"
我建议遇到此问题的每个人都对他们进行评论,以便他们对此问题有所作为。 或尝试使用较低版本。
答案 3 :(得分:0)
使用CKEditor Upload Image plugin。
我们有同样的问题。添加了插件和图片上传和下载API操作。
然后从编辑器中删除过去的按钮。
config.removeButtons = 'Paste,PasteText,PasteFromWord';
将以下代码添加到CKEditor config.js
config.extraPlugins = 'uploadimage';
config.uploadUrl = '/uploader/upload.php';
config.filebrowserUploadUrl = '/uploader/upload.php';
然后,使用CTRL + V粘贴单词doc中的图像。
我正在使用MVC5。所以配置是
config.extraPlugins = 'uploadimage';
config.uploadUrl = '/CkEditorUploadSupport/UploadImage';
config.filebrowserUploadUrl = '/CkEditorUploadSupport/UploadImage';
MVC控制器代码; (项目“控制器”文件夹下的控制器名称“ CkEditorUploadSupport”)
public JsonResult UploadImage()
{
if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
{
var file = System.Web.HttpContext.Current.Request.Files["upload"];
var targetLocation = @"D:\CKTestFolder";
if (!Directory.Exists(targetLocation))
{
Directory.CreateDirectory(targetLocation);
}
var pattern = new Regex(@"[:!@#$%^&*()}{|\"":?><\[\]\\;'/,~]");
var modifiedFileName = pattern.Replace(file.FileName, "");
modifiedFileName = modifiedFileName.Replace("\"", " ");
modifiedFileName = modifiedFileName.Replace("4â€Â", " ");
// Some browsers send file names with full path.
// We are only interested in the file name.
var physicalPath = Path.Combine(targetLocation, modifiedFileName);
var fileName = Path.GetFileName(physicalPath);
var newName = fileName;
while (System.IO.File.Exists(physicalPath))
{
var newFileName = Path.GetFileNameWithoutExtension(fileName)
+ "_" + RandomString(3) +
Path.GetExtension(fileName);
physicalPath = Path.Combine(targetLocation, newFileName);
newName = newFileName;
}
file.SaveAs(physicalPath);
var response = new
{
uploaded = 1,
fileName = newName,
url = "/CkEditorUploadSupport/OpenImage?imageName=" + newName
};
return Json(response);
}
var response2 = new
{
uploaded = 0,
message = "Upload Error.."
};
return Json(response2);
}
public ActionResult OpenImage(string imageName)
{
var targetLocation = @"D:\CKTestFolder";
var physicalPath = Path.Combine(targetLocation, imageName);
if (!System.IO.File.Exists(physicalPath))
{
var response2 = new
{
uploaded = 0,
message = "File Not Found"
};
return Json(response2);
}
string mimeType = MimeMapping.GetMimeMapping(imageName);
return base.File(physicalPath, mimeType);
}
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}