Hello guys,
I'm trying to make an application where the user needs to write an essay but for that I need to disable the cut, copy and paste keys and, in addition, make a word counter including spaces, commas and other characters. Attached is the tests I'm trying to perform but without success.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="cadRedacao.aspx.vb" Inherits="publico_cadRedacao" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="../bootstrap-4.5.2-dist/css/bootstrap.css" rel="stylesheet" />
<script src="../bootstrap-4.5.2-dist/js/bootstrap.min.js"></script>
<a href="../bootstrap-4.5.2-dist/js/bootstrap.bundle.min.js.map">../bootstrap-4.5.2-dist/js/bootstrap.bundle.min.js.map</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="../CPF_CNPJ.js"></script>
<script src="../Funcoes.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input:text').bind('cut copy paste', function(e) {
e.preventDefault();
alert("As opções de Recortar / Copiar / Colar foram desabilitadas");
});
});
</script>
<script language="javascript" type="text/javascript">
function countChars(countfrom, displayto) {
var len = document.getElementById(countfrom).value.replace(/^\s+|\s+$/g,'').length;
document.getElementById(displayto).innerHTML = "Nº de Dígitos: " + len;
document.getElementById('<%= hfDigitos.ClientID %>').value = len;
if (len == 0)
{
document.getElementById(displayto).innerHTML = "";
document.getElementById('divContar').className = 'contar1';
} else
if (len > 0 && len < 1000)
{
document.getElementById('divContar').className = 'contar1';
} else
if (len > 0 && len <= 1000)
{
document.getElementById('divContar').className = 'contar2';
} else
if(len > 1000 && len <=1500)
{
document.getElementById('divContar').className = 'contar2';
} else
if(len > 1500)
{
document.getElementById('divContar').className = 'contar3';
};
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True">
</asp:ScriptManager>
</div>
<div class="container">
<div class="row">
<div class="col-sm-12">
<div style="background-color: #5A9B64; color: #fff; background-image: url(http://localhost:19397/imagens/logocentec_branca.png); background-position:left center; background-repeat:no-repeat; background-size:contain; padding:10px; margin-bottom:20px; height:50px; text-align:right;">
<h3 style="text-align:right;">VESTIBULAR ONLINE</h3>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="h3">REDAÇÃO</div>
</div>
<div class="col-sm-6">
<div class="h3" style="text-align:right;">
<asp:UpdatePanel ID="upContador" runat="server">
<ContentTemplate>
<div><asp:Label ID="LbContador" runat="server" ></asp:Label></div>
<div><asp:HiddenField ID="hfContador" runat="server" /></div>
<div><asp:HiddenField ID="hfDigitos" runat="server" /></div>
<div><asp:Timer ID="Timer1" runat="server"></asp:Timer></div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
<div class="row" style="margin:20px 0px 20px 0px !important;">
<div class="col-sm-12">
<div class="form-panel">
<div class="row">
<div class="col-sm-3">
<div>CPF do candidato:</div>
<div><asp:Label ID="LbCPF" runat="server" CssClass="form-control" ></asp:Label></div>
</div>
<div class="col-sm-9">
<div>Nome do candidato:</div>
<div><asp:Label ID="LbNome" runat="server" CssClass="form-control" ></asp:Label></div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div>Tema da sua redação:</div>
<div><asp:Label ID="LbTema" runat="server" CssClass="form-control" ></asp:Label></div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div>
<asp:UpdatePanel ID="upInicio" runat="server">
<ContentTemplate>
<asp:Button ID="BtnIniciar" runat="server" CssClass="btn btn-success small" Text="Iniciar" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div>
<asp:TextBox ID="comentario" runat="server" TextMode="MultiLine" CssClass="form-control-textarea" style="min-height:300px;" onkeydown="countChars('comentario', 'LbContar');" onmouseout="countChars('comentario', 'LbContar');" ></asp:TextBox>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
It worked perfectly except in one browser - Brave. It has an option called "Force Paste" that allows the user to paste any text there. I know that most users use Chrome, Mozilla, Edge, Opera. Well, here's the tip here, if anyone in the group already has this solution, please make it available.
Grateful, Ilano