简单的JavaScript密码保护在移动平台上不起作用

Simple JavaScript Password protection not working on mobile platform

本文关键字:平台 不起作用 移动 JavaScript 密码保护 简单      更新时间:2023-09-26
<script language="JavaScript"> 
var password; 
var pass1="apple"; 
password=prompt('Password?',' '); 
if (password!=pass1) {window.location="WRONG.html";}
</script>

此代码在桌面Chrome,Firefox,safari等上运行良好。 但是当我在移动浏览器(例如移动浏览器或移动野生动物园)中加载页面时,每次都会被重定向到"错误.html"。 我错过了什么?

从 prompt() 的第二个参数中取出空格。 出于某种原因,移动平台保留了它,并且额外的空间使比较总是评估为错误。 此外,这是一个非常糟糕的安全方案。 只是说'。

<script language="JavaScript"> 
var password; 
var pass1="apple"; 
password=prompt('Password?',''); 
if (password!=pass1) {window.location="WRONG.html";}
</script>