2012-08-29 20 views

回答

0

截至Intercept paste event in Javascript

注意到@maerics您可以通过附加一个“onpaste”处理程序拦截粘贴事件并通过IE或使用“window.clipboardData.getData(‘文本’)”得到粘贴的文本“其他浏览器中的”event.clipboardData.getData('text/plain')“。

,例如:

var myElement = document.getElementById('pasteElement'); 
myElement.onpaste = function(e) { 
    var pastedText = undefined; 
    if (window.clipboardData && window.clipboardData.getData) { // IE 
    pastedText = window.clipboardData.getData('Text'); 
    } else if (e.clipboardData && e.clipboardData.getData) { 
    pastedText = e.clipboardData.getData('text/plain'); 
    } 
    alert(pastedText); // Process and handle text... 
    return false; // Prevent the default handler from running. 
}; 
相关问题