我的 Javascript 代码在 IE 中不起作用,但在其他浏览器中工作正常
我使用以下 Javascript 来密码保护我的网页,但它不适用于 IE,尽管它适用于 Chrome 和 Firefox。
<script language="JavaScript">
var password;
var pass1="PASSWORD-HERE";
password=prompt('Whats The Magic Word?',' ');
if (password==pass1) alert('That Is Correct!');
else {
window.location="SITE-LINK";
}
</script>
怎么了?
请查看链接:http://www.xuanyinwen.com/test3.html 它适用于 Firefox 和 Chrome,但不适用于 IE,当您在 IE 中打开链接时,它不会收到询问密码的消息,并且会自动转到 SITE-LINK。 我知道这个脚本不是很安全,但我只想用它进行基本保护,只是想让它发挥作用。感谢您的帮助!
I used the following Javascript to password protect my webpage but it's not working for IE, although it works fine for Chrome and Firefox.
<script language="JavaScript">
var password;
var pass1="PASSWORD-HERE";
password=prompt('Whats The Magic Word?',' ');
if (password==pass1) alert('That Is Correct!');
else {
window.location="SITE-LINK";
}
</script>
What is wrong?
Please check out the link: http://www.xuanyinwen.com/test3.html
it work on Firefox and chrome but not IE, when you open the link in IE, it got no message pot up asking for the password, and will automatic go to SITE-LINK.
I know this script is not very secure, but I just want use it for a basic protect, just want make it work. thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
不同之处在于您正在设置
href
属性。顺便说一句,我在 IE9 beta 中对此进行了测试,它有效。
Try this:
The difference is that you are setting the
href
property instead.btw I tested this in IE9 beta and it works.
我个人不会只使用 javascript 来保护密码......尤其是当它可以公开显示时。
检查 active x 是否被禁用。适用于 IE 7/8 和怪异模式,对我来说
IE 关闭弹出窗口阻止并自动启用活动 x:
打开 IE 转到工具 -> Internet 选项 -> 高级 -> 安全确保允许允许活动 x。然后转到“工具”->“Internet 选项”->“隐私”并确保弹出窗口未被阻止。
警告:我不建议这样做!测试后请使用默认值我将不承担任何责任
i personally wouldn't just use javascript for password protection...especially when it can be displayed publically.
Check to see if active x is diabled. works on IE 7/8 and quirk mode for me
IE Turn off popup-block and auto enable active x:
open IE go to Tools->Internet Options->Advanced->Security make sure allow active x are allowed. Then go to Tools->Internet Options->privacy and make sure pop up is not blocked.
WARNING: I DO NOT RECOMMAND DOING THIS! AFTER TESTING PLEASE USE DEFAULT I WILL NOT BE RESPONSIBLE
试试这个:
区别在于 3 个等号而不是 2 个。JavaScript 中的双等号让运行时尝试对要比较的项目进行类型强制,而使用 3 个等号时,它会按原样比较它们。
然而,正如上面的评论者所指出的,使用 javascript 作为唯一的密码保护充其量是天真的。
Try this:
The difference being 3 equals signs instead of 2. Double-equals in JavaScript lets the runtime try to do type coercion on the items being compared, while with three equals it compares them exactly as-is.
However, as the commenter above noted, using javascript as your only password protection is naive at best.