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 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

PREVIOUS NEXT
Code Example
Javascript :: regex expression to match domain name 
Javascript :: nextjs global scss variables 
Javascript :: merge array of objects javascript 
Javascript :: classiceditor is not defined using npm 
Javascript :: array js fill 
Javascript :: javascript get sub array 
Javascript :: how to make a div appear when clicked on in javascript 
Javascript :: Uncaught (in promise) SyntaxError: Unexpected token O in JSON at position 0 
Javascript :: how to get file type in javascript 
Javascript :: js filter out doubles 
Javascript :: how to start a node server 
Javascript :: get the state of a checkbox 
Javascript :: react native getstream 
Javascript :: run function then empty it js 
Javascript :: javascript json stringify indented 
Javascript :: vue router refresh page not found 
Javascript :: format date javascript 
Javascript :: two array in one js 
Javascript :: formgroup is not property of form angular 
Javascript :: how to sort an array of object 
Javascript :: uppercase in javascript 
Javascript :: js math function that returns smallest value 
Javascript :: array reverse in javascript 
Javascript :: js loading spinner 
Javascript :: reducer in react example 
Javascript :: set input value vanilla js 
Javascript :: get thumbnail from video js 
Javascript :: deduplicate array javascript 
Javascript :: javascript sum of arguments 
Javascript :: angular hostlistener 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =