Html button code is as follows, I tried a simple onclick function on the button and an event on the second button
<button onclick="myFunction()">Click me</button> <button id="button">Paste</button>
Javascript code is as follows
function myFunction() { var clipboarddata = window.event.clipboardData.getData('text'); console.log("paste value" + clipboarddata); } var button = document.getElementById("button"); button.addEventListener("click", function(event){ alert(event.target); event.preventDefault(); var clipboarddata = window.event.clipboardData.getData('text'); console.log("paste value" + clipboarddata); });
I get the same error both ways