Reputation: 265
Im trying to create a script that will grab the users clipboard data on pageload, and show up in a textbox where they can press Submit.
Ive looked all over google and can not find the solution. I was wondering if this is possible?
Upvotes: 1
Views: 2943
Reputation: 46060
Reading the clipboard is disabled by default in most browsers (for security reasons). You could try this (jQuery) but it wont work unless the user has clipboard access enabled.
<script type="text/javascript">
$(() => {
if (typeof window.clipboardData === 'undefined') {
alert('clipboard disabled')
} else {
$('#text_area').val(window.clipboardData.getData());
}
});
</script>
Upvotes: 0
Reputation: 4319
It isn't possible. Sorry. But you can change the clipboard data with javascript, just not read it.
Upvotes: 0
Reputation: 45578
Afaik it's not possible for security reasons - imagine the case that you just copy-and-pasted some password and a website steals it.
Upvotes: 1