PUG
PUG

Reputation: 351

Javascript :: Paste clipboard to textarea

<!DOCTYPE html>
<html>
<body>


<form action=# method=post name=test>
<textarea name=numb id=numb rows=4 cols=50></textarea>
<input type=submit>
</form>

<script>

window.onload=function(){

document.getElementById("numb").value = window.clipboardData.getData('Text');

}

</script>
</body>
</html>

Title is pretty much self explanitory... I want to be able to paste the clipboard to the textarea onload... seems like a simple task but for some reason it's not working :/

Upvotes: 2

Views: 2390

Answers (1)

Mikko Pitk&#228;nen
Mikko Pitk&#228;nen

Reputation: 23

That seems like a huge security issue if your javascript could access users clipboard right of the bat on onLoad :) So at the moment that can't be done directly via javascript. Maybe you should think alternative routes to that problem, like guiding people how to paste to that field e.g. via keyboard shortcuts.

Upvotes: 2

Related Questions