Prevent Copying and Pasting within the Text Editor

@if (Model.CanMaintainNcrLineManagement) {
<tr>
  <td>@Html.TextAreaFor(model => model.Description, new { id = "txArNcrLineDescriptionValue", @style = "height:520px" })</td>
</tr>
} else {
<tr class="read-only-editor">
  <td>@Html.TextAreaFor(model => model.Description, new { id = "txArNcrLineDescriptionReadOnly", @style = "height:520px" })</td>
</tr>
}

I am looking to prevent users from copying and pasting text in the editor box. Despite trying the codes below, it hasn't been successful. Any suggestions for a solution?

$('body').bind('copy paste', function(e) {
  e.preventDefault();
  return false;
});
<body oncopy="return false" oncut="return false" onpaste="return false">

Answer №1

Make sure your code is updated and your text editor is enclosed within the body tag to block any content inside it.

<body onselectstart="return false" onpaste="return false;" onCopy="return false" onCut="return false" onDrag="return false" onDrop="return false">

Answer №2

After thorough testing across multiple browsers including Chrome 66.0.3359.181, I.E. 11, and FireFox 59.0.3, I have confirmed that the code effectively disables copying and pasting in both the body and input fields.

 $('body').bind('copy paste', function (e) {
        e.preventDefault(); return false;
    });
<body oncopy="return false" oncut="return false" onpaste="return false">

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to populate HTML content retrieved from my MySQL database

Currently, I am attempting to retrieve HTML content stored in my MySQL database using nodejs. The products are being retrieved from the database successfully. export async function getAllProducts() { try { const response = await fetch('ht ...

Ways to retrieve a specific value from a JSON dataset

I currently have an Ajax live search script with multiple text inputs for searching products. The live search functionality works perfectly, but I have a query: If I decide to change the name of a product, how can I go back to the previous page and re-s ...

Troubleshooting: Navbar Hover Effect in Tailwind CSS Not Functioning as Expected

This week, I've been working on building a navbar and it seems like the layout is coming together nicely. However, I've encountered a couple of small issues with the hover effect and the links for the menu items on the left and the logo in the ce ...

Get the image from the express route

Currently, I am running an express server with the following route: exports.getUserFile = function (req, resp) { let filePath = path.join(__dirname, 'storage', req.params.fileName); resp.download(filePath); }); } Within my web app ...

What is the purpose of using $ symbols within NodeJS?

Lately, I've been attempting to grasp the ins and outs of using/installing NodeJS. Unfortunately, I'm feeling a bit lost due to tutorials like the one found here and their utilization of the mysterious $ symbol. Take for instance where it suggest ...

Resolving the issue of data transmission within Yii2's framework: Page-to-page data

I'm currently using Yii2-advanced-app and I have encountered an issue. I want to pass the selected value from a dropdown menu to a PHP code that displays a list with checkboxes on the same page. Here is an image for reference on what I am trying to ac ...

methods for selecting the final class within a div

Within the given example, I am trying to extract the last class of a div which is named tex1. My goal is to display it in the console using jQuery like so: let last = $('#tex').attr('class').last(); console.log(last); // error <s ...

Incorporating dynamic dictionary fields in Reactive and pushing them into an established FormControl

I am attempting to dynamically populate my reactive form with varying fields based on user selection. Here is an example of the fields I have: fields = [{ df_id: 48, df_name: "Phone Number", df_type: "text", ...

exclude a few countries from ngx-intl-tel-input

I'm facing an issue where I need to remove certain countries, like Mexico, from the list displayed in ngx-intl-tel-input. Even after trying the 'excludeCountries' option, it doesn't seem to be working for me. Below is a snippet of my ...

The bond between Node.js and Express

I'm intrigued by the relationship between Node.js and Express. Here is my Node.js server creation code: const https = require('https'); const fs = require('fs'); const options = { key: fs.readFileSync('./https1/key.pem&ap ...

CSS posing a variety of issues: opacity affecting text elements as well as misplacement of divs

<!DOCTYPE html> <html> <head> <title>Title</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <style type="text/css"> body { backgr ...

Is there a way to retrieve two arrays in an Ajax request?

JAVASCRIPT CODE: $.ajax({ url: 'assignavailtrainers.php', data: {action:'test'}, type: 'post', success: function(data) { } }); PHP CODE: <?php $username = "trainerapp"; ...

JavaScript Function to Retrieve URL Parameter in PHPIn this tutorial

I'm currently working on an HTML5 game where each level has its own dedicated HTML page. The results of each level are saved in a JavaScript variable. My question is, how can I pass this information to the next page using the URL? I was considering ...

Storing data in JSON format and retrieving it using Javascript

My challenge involves plotting a chart using values from an object's list in my view with High Chart. However, I face the issue of accessing my model from JavaScript. public class MortgageCalculator { public List<double> interest_month = new ...

Utilizing jQuery's $.get method to incorporate an Asp.net Mvc Web Api Http Get request

Curious about the correct method for accessing an ASP.Net Web API HTTP GET method in an MVC controller class from a Javascript file in my current scenario. The code snippet below is within a function in the document.ready body. Javascript: var Id ...

Unable to remove class using jQuery's .removeClass

I have a function that dynamically adds or removes classes from an element based on scroll position and direction. Everything was functioning correctly until I introduced a delay when adding the scrolled class. Now, the final .removeClass('scrolled&a ...

Extract latitude and longitude coordinates from a dataset by applying a rectangular filter

I have developed a program that extracts information from a JSON object and showcases it on a webpage, specifically focusing on Public Bike Stations. The JSON object includes the latitude and longitude of each station, making it easy to locate them. My cu ...

Extracting Values from JSON Array using Form Input Text

After designing a form for my web application, I encountered a situation where some fields needed to be populated with values from a JSON array retrieved from the treatment table in the database. {"treatment":[ { "id" : 1, "name" : "Leg Training" }, ...

retrieve the complete webpage content, encompassing the .html file, images, .js files, css stylesheets, and more

I'm currently working on a project and could use some assistance. Is there a method available to download an entire page, including the .html file, images, .js files, css, etc., using PHP, JavaScript, or AJAX? <html> <body> & ...

sending a transformed javascript array from php to a javascript function

I'm looking for a way to pass a JavaScript array (that has been converted from PHP to JS) from PHP code to a JavaScript function. <?php // Convert PHP array to JavaScript array $php_array = array('he','hi','hello'); ...