公司最近用redmine,需要加入image_clipboard_paste插件完善截屏粘贴功能
但是这个插件只能支持火狐和谷歌浏览器,对于一个传统软件公司,还有好多用户
必须使用ie8或者更低的版本,所以粘贴截屏功能还必须兼容ie8。经过几天的调试,
发现是js文件中addEventListener和removeEventLitsener方法对ie8不兼容,故将
这两个方法换成了attachEvent和detachEvent方法,但实际情况发现这样修改后
剪切板可以正常显示,但是截屏后ctrl+v没有任何反应,急求大神指点!!!
更改后代码如下:
var pasteCatcher;
function initPasteListener() {
// We start by checking if the browser supports the
// Clipboard object. If not, we need to create a
// contenteditable element that catches all pasted data
if (!window.Clipboard) {
pasteCatcher = document.createElement("div");
// Firefox allows images to be pasted into contenteditable elements
pasteCatcher.setAttribute("contenteditable", "");
pasteCatcher.setAttribute("id", "cbp_paste_catcher");
// We can hide the element and append it to the body,
dialog.appendChild(pasteCatcher);
// as long as we make sure it is always in focus
document.attachEvent("click", focusCatcher);
setTimeout(focusCatcher, 50);
}
// Add the paste event listener
window.attachEvent("paste", pasteHandler);
};
function deinitPasteListener() {
window.detachEvent("paste", pasteHandler);
if (pasteCatcher) {
document.detachEvent("click", focusCatcher);
dialog.removeChild(pasteCatcher);
delete pasteCatcher;
}
};