是否有可能限制每分钟的最大条目在html中的文本输入?



我即将完成我自己用HTML写的网站,我想知道如何使它安全。到目前为止,我已经限制了搜索栏的最大长度并禁用了特殊字符。是否可以限制每分钟输入文本的最大条目数?如果有人对我如何使网站安全有任何其他建议,请告诉我!谢谢!

当然你必须决定如何存储变量,因为重新加载页面会重置它,你可以使用cookielocalStorage

const out = document.querySelector('#output')
const txt = document.querySelector('#text')
const btn = document.querySelector('#btn')
btn.addEventListener('click', enter, 'false');
const time = document.querySelector('#time')
let allowTime = new Date().getTime();
const diff = (end, start) => (end - start) / 1000
const lock = () => {
const i = setInterval(()=> {
const now = Date.now()
const wait = diff(allowTime, now)
if (wait <= 0) {
time.textContent = 0;
allowTime = now;
clearInterval(i);
} else {
time.textContent = Math.floor(wait);
} 
},
1000)
} 
function enter(){
const now = Date.now();
if (diff(allowTime, now ) <= 0)  {
out.textContent += txt.value  + 'n';
txt.value = '';
allowTime = now + (1000 * 20) // <----- wait 20 seconds
lock()
}
}
<pre id="output">
</pre>
<p>wait: <span id="time">0</span> seconds</p>  
<input type="text" id="text">
<button id="btn">send</button>

最新更新