Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Just Get copyed text from clipboard on Chrome

Can you tell me how can I just get text who is copied in clipboard. I don't want to make a copy because data are copied from Excel. In IE I use :

  var clipText = window.clipboardData.getData('Text');

And it's work perfect. Is it possible in chrome ? or maybe Firefox ?

Thanks for advance

like image 291
clementine Avatar asked Jul 12 '16 10:07

clementine


1 Answers

The window.clipboardData object is only available in IE. It seems like a big security vulnerability to me for a website to be able to access your clipboard data, especially without you knowing. According to the specification, it's mostly deprecated as of Microsoft Edge.

Instead, you can access the data by listening to the paste event:

document.addEventListener('paste', function (event) {
  var clipText = event.clipboardData.getData('Text');
});
like image 181
Gideon Pyzer Avatar answered Sep 28 '22 07:09

Gideon Pyzer