Joseph
Joseph

Reputation: 265

Grab Clipboard data on page load

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

Answers (3)

Petah
Petah

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

alexyorke
alexyorke

Reputation: 4319

It isn't possible. Sorry. But you can change the clipboard data with javascript, just not read it.

Upvotes: 0

thejh
thejh

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

Related Questions