Tutorial :Copy text from TextArea into clipboard using JavaScript on Non-Microsoft platforms [closed]


I am looking for a javascript function which can copy contents from TextArea into clipboard. On microsoft platform the function works fine, but it fails when I switch to non-microsoft platform such as, FireFox or Safari.
I referred this link for the function.

If anyone knows the solution for this, please help me out.
Thanks in advance.


A pure JavaScript solution for copying the contents of a textarea to the clipboard when the user clicks on the textarea:

<script>    function copySelectionText(){      var copysuccess // var to check whether execCommand successfully executed      try{          copysuccess = document.execCommand("copy") // run command to copy selected text to clipboard      } catch(e){          copysuccess = false      }      return copysuccess  }    function copyfieldvalue(e, id){      var field = document.getElementById(id)      field.select()      var copysuccess = copySelectionText()  }    var bio = document.getElementById('mybio')  bio.addEventListener('mouseup', function(e){      copyfieldvalue(e, 'mybio')      var copysuccess = copySelectionText() // copy user selected text to clipboard  }, false)    </script>  

Note: If you want to copy only parts of the textarea contents to clipboard, the tutorial Reading and copying selected text to clipboard using JavaScript has more info on that.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »