Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Copy To Clipboard

const copyToClipboard = (text) => navigator.clipboard.writeText(text);

copyToClipboard("Hello World");
Comment

Copy to clipboard

// Method 4 : Copying from input
<head>
  <script>
function copyToCliBoard() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  copyText.setSelectionRange(0, 99999); /* For mobile devices */
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}
</script>
</head>
<body>
<input type="text" value="Some Context" id="myInput">
<button onclick="copyToCliBoard()">Copy text</button>
</body>
Comment

copy to clipboard

navigator.clipboard.writeText('Text To Copy');
Comment

copy to clipboard

const copyToClipboard = (text) =>
  navigator.clipboard?.writeText && navigator.clipboard.writeText(text);
// Testing
copyToClipboard("Hello World!");
Comment

copy text to the clipboard

const copyToClipboard = str => {
  if (navigator && navigator.clipboard && navigator.clipboard.writeText)
    return navigator.clipboard.writeText(str);
  return Promise.reject('The Clipboard API is not available.');
};
Comment

Copy to Clipboard

const copyToClipboard = (text) => navigator.clipboard.writeText(text);

copyToClipboard("Hello World");
Comment

copy to clipboard

methods: {
  async copyURL(mytext) {
    try {
      await navigator.clipboard.writeText(mytext);
      alert('Copied');
    } catch($e) {
      alert('Cannot copy');
    }
  }
}
Comment

How to copy a string to the clipboard?

const copyToClipboard = str => {
  const el = document.createElement('textarea');
  el.value = str;
  el.setAttribute('readonly', '');
  el.style.position = 'absolute';
  el.style.left = '-9999px';
  document.body.appendChild(el);
  const selected =
    document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
  if (selected) {
    document.getSelection().removeAllRanges();
    document.getSelection().addRange(selected);
  }
};

// Example
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
Comment

PREVIOUS NEXT
Code Example
Javascript :: jqueyr element is hide 
Javascript :: json placholder 
Javascript :: "SyntaxError: Unexpected token o in JSON at position 1 
Javascript :: how to compare two time in moment js 
Javascript :: map index 
Javascript :: javascript open pdf in new tab 
Javascript :: fetch function javascript 
Javascript :: get version from package.json 
Javascript :: foreach over array javascript 
Javascript :: how to get the data from url in javascript 
Javascript :: how to run commands in the command prompt using javascript 
Javascript :: Repeat a String Repeat a String 
Javascript :: difference between let and var in javascript 
Javascript :: javascript how to sort alphabetically 
Javascript :: javascript array size 
Javascript :: filter by keyname javascript 
Javascript :: add required attribute javascript 
Javascript :: updateone mongoose example 
Javascript :: csv to json python 
Javascript :: moment get timezone 
Javascript :: how to move div using jquery 
Javascript :: axio post file 
Javascript :: angularjs date filter 
Javascript :: capacitor.ionicframework.com to apk 
Javascript :: how to get thumbnail image from video file in javascript 
Javascript :: vue mounted 
Javascript :: string to currency javascript 
Javascript :: js notifications 
Javascript :: javascript console log whole array 
Javascript :: react-file-base64 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =