Is it possible to read the clipboard in Firefox, S

2019-01-04 01:06发布

I'm trying to read the contents of the clipboard using Javascript. With Internet Explorer it's possible using the function

window.clipboardData.getData("Text")

Is there a similar way of reading the clipboard in Firefox, Safari and Chrome?

4条回答
欢心
2楼-- · 2019-01-04 01:35

NO. And if you do find a hack (e.g. old version of flash) do not depend on it.

Can I ask why you want to read from the clipboard? If the user wants to pass along the clipboard contents, all they need to do is paste.

查看更多
Animai°情兽
3楼-- · 2019-01-04 01:36

Online Spreadsheets hook Ctrl+C, Ctrl+V events and transfer focus to a hidden TextArea control and either set it contents to desired new clipboard contents for copy or read its contents after the event had finished for paste.

查看更多
贪生不怕死
4楼-- · 2019-01-04 01:53

I believe people use a hidden Flash element to read the clipboard data from the browsers you mentioned.

查看更多
做自己的国王
5楼-- · 2019-01-04 01:54

Safari supports reading the clipboard during onpaste events:

Information

You want to do something like:

someDomNode.onpaste = function(e) {
    var paste = e.clipboardData && e.clipboardData.getData ?
        e.clipboardData.getData('text/plain') :                // Standard
        window.clipboardData && window.clipboardData.getData ?
        window.clipboardData.getData('Text') :                 // MS
        false;
    if(paste) {
        // ...
    }
};
查看更多
登录 后发表回答