gpt4 book ai didi

javascript - 如何禁止在表单中复制/粘贴?

转载 作者:行者123 更新时间:2023-11-30 12:45:27 28 4
gpt4 key购买 nike

我正在使用 Meteor 开发一个聊天应用程序,我不希望用户能够出于明显的垃圾邮件原因将内容复制/粘贴到表单中。这可能吗?这是我用来运行聊天应用程序的代码:

Javascript:

// render all of our messages in the ui
Template.chatBox.helpers({
"messages": function() {
return chatCollection.find();
}
});

// get the value for handlerbar helper user
Template.chatMessage.helpers({
"user": function() {
if(this.userId == 'me') {
return this.userId;
} else if(this.userId) {
getUsername(this.userId);
return Session.get('user-' + this.userId);
} else {
return 'anonymous-' + this.subscriptionId;
}
}
});

// when Send Chat clicked at the message to the collection
Template.chatBox.events({
"click #send": function() {
if (Meteor.user() == null) {
alert("You must login to post");
return;
}
$('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast");
var message = $('#chat-message').val();

// check to see if the message has any characters in it
if (message.length < 1) {
alert("You must enter a message to post.");
return;
}

chatCollection.insert({
userId: 'me',
message: message
});
$('#chat-message').val('');

//Validation
var bot =Check_bots();

if(bot==false)
{
//add the message to the stream
chatStream.emit('chat', message);
}
else
{
alert("Slow down! No need to post that fast.");
return false;
}
},

"keypress #chat-message": function(e) {
if (Meteor.user() == null) {
alert("You must login to post");
return;
}
if (e.which == 13) {

//Validation
var bot =Check_bots();

if(bot==false)
{
$('#messages').animate({"scrollTop": $('#messages')[0].scrollHeight}, "fast");
console.log("you pressed enter");
e.preventDefault();
//repeat function from #send click event here
var message = $('#chat-message').val();

// check to see if the message has any characters in it
if (message.length < 1) {
alert("You must enter a message to post.");
return;
}

chatCollection.insert({
userId: 'me',
message: message
});
$('#chat-message').val('');

//add the message to the stream
chatStream.emit('chat', message);
}
else
{
alert("Slow down! No need to post that fast.");
return false;
}
}
}
});

chatStream.on('chat', function(message) {
chatCollection.insert({
userId: this.userId,
subscriptionId: this.subscriptionId,
message: message
});
});

var lastintime=0;
var defference=0;
var msg_count=0;

function Check_bots()
{
var seconds = new Date().getTime() / 1000;
seconds=parseInt(seconds);

if(lastintime < seconds)
{
defference = seconds -lastintime;
lastintime=seconds;

if(defference<=5 && msg_count>=3)
{
return true;
}
else
{
return false;
}
}
}

我什至不知道从哪里开始。你如何防止复制/粘贴?

最佳答案

这不是一个好主意。 Internet Explorer 有一个 onpaste 事件,并且有一个 convoluted implementation on Stack Overflow , 但总的来说它很困惑,跨越了网页设计中通常不应跨越的线,不可能在所有浏览器中完全实现,并且可以轻松绕过。

设置字符速率限制并检测垃圾邮件的危险信号(例如高链接密度和重复)是一个更好的主意。

关于javascript - 如何禁止在表单中复制/粘贴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22651257/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com