[英]My Javascript code does not work in IE but works fine in other browsers
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. 我使用以下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>
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. 请查看链接: http : //www.xuanyinwen.com/test3.html它可以在Firefox和chrome上运行,但不能在IE上运行,当您在IE中打开链接时,它没有提示输入密码的消息,并且自动转到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!
谢谢你的帮助!
Try this: 尝试这个:
<script>
prompt('Password:') === '1234' ?
alert('Correct!') :
window.location.href = 'http://www.google.com';
</script>
The difference is that you are setting the href
property instead. 不同之处在于,您改为设置
href
属性。
btw I tested this in IE9 beta and it works. 顺便说一句,我在IE9 beta中对此进行了测试,并且可以正常工作。
i personally wouldn't just use javascript for password protection...especially when it can be displayed publically. 我个人不会仅仅使用javascript来保护密码...尤其是当它可以公开显示时。
Check to see if active x is diabled. 检查是否激活了x。 works on IE 7/8 and quirk mode for me
对我来说适用于IE 7/8和怪癖模式
IE Turn off popup-block and auto enable active x: IE关闭弹出框并自动启用活动x:
open IE go to Tools->Internet Options->Advanced->Security make sure allow active x are allowed. 打开IE,转到“工具”->“ Internet选项”->“高级”->“安全性”,确保允许“允许活动x”。 Then go to Tools->Internet Options->privacy and make sure pop up is not blocked.
然后转到工具-> Internet选项->隐私,并确保弹出窗口未被阻止。
WARNING: I DO NOT RECOMMAND DOING THIS! 警告:我不建议您这样做! AFTER TESTING PLEASE USE DEFAULT I WILL NOT BE RESPONSIBLE
经过测试后,请使用默认设置,我将不负责任
Try this: 尝试这个:
<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>
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. 区别是3等于2,而不是2。JavaScript中的double-equals允许运行时尝试对要比较的项目进行类型强制转换,而使用3等于则按原样对它们进行比较。
However, as the commenter above noted, using javascript as your only password protection is naive at best. 但是,正如上面的评论者所述,使用javascript作为唯一的密码保护充其量是幼稚的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.