Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let b= document.querySelector('pre'),
- c= 'i am stupid';
- b.addEventListener('copy',
- function(e){
- e.clipboardData.setData('text', c);
- e.preventDefault();
- });
- b.onclick= function() {
- try{ navigator.clipboard.writeText(c);
- alert('Copied!');
- }
- catch(err){
- try{let inp =document.createElement('input');
- document.body.appendChild(inp)
- inp.value= c; inp.select();
- document.execCommand('copy',false);
- inp.remove();
- alert('Copied!!');}
- catch(err){
- try{let e= window.getSelection(),
- f= document.createRange();
- f.selectNodeContents(b);
- e.removeAllRanges();
- e.addRange(f);
- document.execCommand("copy");
- alert('Copied!!!');}
- catch(err){alert("Couldn't copy because: "+ err.message)}
- }
- }
- };
RAW Paste Data