Error in pasting clipboard data API functionality in javascript Uncaught TypeError: Cannot read properties of undefined (reading 'getData')
P粉043432210
P粉043432210 2024-04-04 10:23:52
0
1
598

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

P粉043432210
P粉043432210

reply all(1)
P粉232409069

You can use navigator.clipboard.readText instead.


sssccc
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template