密码保护 html 页面
我需要对任意 html 文件添加一些简单的密码保护。它确实需要安全,但只需将随机的无赖拒之门外即可。我尝试使用下面的JS:
var password;
var thePassword="secretpassword";
password=prompt('Enter Password',' ');
if (password==thePassword) { alert('Correct Password! Click OK to Enter!'); }
else { window.location="http://www.google.com/"; }
这在Firefox中工作正常,但似乎提示功能在IE中失败,所以我们总是重定向到google...
关于如何使用直接HTML页面进行简单的密码保护有什么建议吗?
编辑:要明确的是,它在 Firefox 中工作正常,在 IE 中甚至不会弹出要求“输入密码”的提示
I need to tack some simple password protection onto arbitrary html files. It does need need to be secure, but just keep out the random roff-raff. I tried using the below JS:
var password;
var thePassword="secretpassword";
password=prompt('Enter Password',' ');
if (password==thePassword) { alert('Correct Password! Click OK to Enter!'); }
else { window.location="http://www.google.com/"; }
This works fine in Firefox, but seems that the prompt function fails in IE and so we always redirect to google...
Any suggestions on how to do a simple password protection using straight HTML pages?
EDIT: to be clear, it works fine in Firefox, and in IE does not even prompt with a popup asking to "Enter Password"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 IE 中对我来说工作得很好。演示:http://jsfiddle.net/U2n3P/
它可能无法正常工作的一个可能原因是您'使用
' '
重新填充提示符中的空格,因此当您开始键入时,末尾可能会有空格。将提示更改为:仅供参考,我知道您说过您不需要超级安全,但您不妨添加一些安全性。获取 MD5 库并执行以下操作:
Works fine for me in IE. Demo: http://jsfiddle.net/U2n3P/
One possible reason it may not be working is that you're populating the prompt with an empty space, by using
' '
, so when you start typing there may be a space at the end. Change the prompt to:FYI, I know you said you didn't need this to be super secure, but you might as well add some security. Get an MD5 library and do, instead:
将安全页面或目录命名为 md5 哈希密码。
Name the secure page or directory the md5 hashed password.