“Zdobądź skopiowany tekst JavaScript” Kod odpowiedzi

JS otrzymuj skopiowany tekst

navigator.permissions.query({name: "clipboard-write"}).then(result => {
  if (result.state == "granted" || result.state == "prompt") {
    /* write to the clipboard now */
  }
});
Modern Mouse

JS otrzymuj skopiowany tekst

function updateClipboard(newClip) {
  navigator.clipboard.writeText(newClip).then(function() {
    /* clipboard successfully set */
  }, function() {
    /* clipboard write failed */
  });
}
Modern Mouse

Zdobądź skopiowany tekst JavaScript

const bodyEle = document.querySelector('body') // Change this 'Body' with any Tag, Class or ID
bodyEle.addEventListener('copy', function(e){
	const selection = document.getSelection() // Catch the Selection
    const selToStr = selection.toString() // Convert Selection to String
    console.log(selToStr) // Display Copied Text
})
Lonely Lynx

Odpowiedzi podobne do “Zdobądź skopiowany tekst JavaScript”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu