Window 粘贴事件侦听器未在 IE 11 中触发
Window Paste Event Listener not firing in IE 11
这是我的代码,在 chrome
中完美运行
public ngOnInit() {
window.addEventListener('paste', this.InsertNewRowsBeforePaste.bind(this));
}
在 Chrome 中,只有当用户在我的组件中选择 Ctrl+V 时才会触发,在本例中是自定义网格
InsertNewRowsBeforePaste(event) {
console.log(event);
console.log(window);
// gets data from clipboard and converts it to an array (1 array element for each line)
let clipboardData = event.clipboardData || event.originalEvent['clipboardData'].getData('text');
if (!clipboardData) {
clipboardData = window['clipboardData'].getData('Text');
}
}
问题出在 IE11 中,InserNewRowsBeforePaste 从未触发,因为我的控制台从不记录事件或 window。这是为什么?
我明白了。您必须在 IE 中捕获将模仿 Ctrl + V 行为的按键按下事件,然后您可以从那里访问剪贴板
this.global = this.renderer.listen('document', 'keydown', (event) => {
if (event.ctrlKey === true && event.key === 'v') {
const clipboardData = window['clipboardData'].getData('Text');
if (clipboardData) {
// Call any method to manipulate the clipboard data here
}
}
});
这是我的代码,在 chrome
中完美运行public ngOnInit() {
window.addEventListener('paste', this.InsertNewRowsBeforePaste.bind(this));
}
在 Chrome 中,只有当用户在我的组件中选择 Ctrl+V 时才会触发,在本例中是自定义网格
InsertNewRowsBeforePaste(event) {
console.log(event);
console.log(window);
// gets data from clipboard and converts it to an array (1 array element for each line)
let clipboardData = event.clipboardData || event.originalEvent['clipboardData'].getData('text');
if (!clipboardData) {
clipboardData = window['clipboardData'].getData('Text');
}
}
问题出在 IE11 中,InserNewRowsBeforePaste 从未触发,因为我的控制台从不记录事件或 window。这是为什么?
我明白了。您必须在 IE 中捕获将模仿 Ctrl + V 行为的按键按下事件,然后您可以从那里访问剪贴板
this.global = this.renderer.listen('document', 'keydown', (event) => {
if (event.ctrlKey === true && event.key === 'v') {
const clipboardData = window['clipboardData'].getData('Text');
if (clipboardData) {
// Call any method to manipulate the clipboard data here
}
}
});