Last active
June 15, 2023 10:30
-
-
Save markylaredo/43f92b19436fc680d853fba0576e7a77 to your computer and use it in GitHub Desktop.
Prevent Copy-Paste in Textarea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>jquery-textarea</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" | |
integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" | |
crossorigin="anonymous" referrerpolicy="no-referrer"></script> | |
</head> | |
<body> | |
<div class="wpforms-container"> | |
<br> | |
<input type="text" placeholder="Type here"> | |
<br> | |
<br> | |
<textarea id="someTextAreaId" placeholder="type your text here" cols="30" rows="10"></textarea> | |
</div> | |
<script type="text/javascript"> | |
//plain javascript prevent user from copying and pasting text | |
const textarea = document.getElementById("someTextAreaId"); | |
textarea.addEventListener('copy', function(e) { | |
e.preventDefault(); | |
console.log(e, "Copying text is not allowed"); | |
}); | |
textarea.addEventListener('paste', function(e) { | |
e.preventDefault(); | |
console.log(e, "Pasting text is not allowed"); | |
}); | |
// const textarea = document.getElementById("someTextAreaId") | |
// jQuery(textarea).on('copy paste', function (e) { | |
// e.preventDefault(); | |
// console.log(e, "copying or pasting text is not allowed"); | |
// }); | |
// jQuery('#someTextAreaId').on('copy paste', function (e) { | |
// e.preventDefault(); | |
// console.log(e, "copying or pasting text is not allowed"); | |
// }); | |
// jQuery(document).ready(function () { | |
// jQuery('.wpforms-container').on('copy', 'input, textarea', function (e) { | |
// e.preventDefault(); | |
// console.log(e, "copying text"); | |
// }); | |
// jQuery('.wpforms-container').on('paste', 'input, textarea', function (e) { | |
// e.preventDefault(); | |
// console.log(e, "pasting text"); | |
// }); | |
// }); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment