Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

copy text to clipboard javascript without input

navigator.clipboard.writeText('the text')
Comment

js copy input value to clipboard

<input type="text" placeholder="Create Password" id="text" readonly>
<script>
  function copyPassword(){
    var copyText = document.getElementById('text')
    copyText.select()
    copyText.setSelectionRange(0, 999)
    document.execCommand("copy")
    console.log(copyText);
  }
</script>
Comment

javascript copy value to clipboard

function fallbackCopyTextToClipboard(text) {
  var textArea = document.createElement("textarea");
  textArea.value = text;
  
  // Avoid scrolling to bottom
  textArea.style.top = "0";
  textArea.style.left = "0";
  textArea.style.position = "fixed";

  document.body.appendChild(textArea);
  textArea.focus();
  textArea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Fallback: Copying text command was ' + msg);
  } catch (err) {
    console.error('Fallback: Oops, unable to copy', err);
  }

  document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
  if (!navigator.clipboard) {
    fallbackCopyTextToClipboard(text);
    return;
  }
  navigator.clipboard.writeText(text).then(function() {
    console.log('Async: Copying to clipboard was successful!');
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
}

var copyBobBtn = document.querySelector('.js-copy-bob-btn'),
  copyJaneBtn = document.querySelector('.js-copy-jane-btn');

copyBobBtn.addEventListener('click', function(event) {
  copyTextToClipboard('Bob');
});


copyJaneBtn.addEventListener('click', function(event) {
  copyTextToClipboard('Jane');
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: discord.js const 
Javascript :: tampermonkey all pages 
Javascript :: telegram web app js 
Javascript :: maxscript saveMaxFile 
Javascript :: mdn javascript console.log(Math.random()); 
Javascript :: javascript values 
Javascript :: javascrpt 
Javascript :: unique in order codewars javascript 
Javascript :: Find all objects in different levels of JSON 
Javascript :: make a circle in javascript 
Javascript :: how to change elemen size in js when custom page width changed 
Javascript :: react animated text yarn package 
Javascript :: Javacript code that delays, based on Milliseconds 
Javascript :: getting ad to close jquery 
Javascript :: grepper answer 
Javascript :: react-select is unable to remove selected option after adding value props 
Javascript :: node middle code for server 
Javascript :: javascript csv einlesen-jqueryAjax 
Javascript :: how to check if a string contains a specific word in javascript 
Javascript :: mdn spread 
Javascript :: solana solana-Web3.js change for devnet lamports to production transaction 
Javascript :: regular expressiong to indentify bible references in a sentence 
Javascript :: save file as get dimensions puppeteer js 
Javascript :: graal.js javascript array in java 
Javascript :: why is necessary to run react-native run 
Javascript :: tower defense bullet following enemy with range javascript 
Javascript :: check variable is array or not in javascript 
Javascript :: Jboss heap dump 
Javascript :: javascript return strung 
Javascript :: float vape pen instructions 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =