我的 Javascript 代码在 IE 中不起作用,但在其他浏览器中工作正常

发布于 2024-10-14 07:36:51 字数 602 浏览 1 评论 0原文

我使用以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

临走之时 2024-10-21 07:36:51

试试这个:

<script>
    prompt('Password:') === '1234' ? 
        alert('Correct!') : 
        window.location.href = 'http://www.google.com';
</script>

不同之处在于您正在设置 href 属性。

顺便说一句,我在 IE9 beta 中对此进行了测试,它有效。

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.

btw I tested this in IE9 beta and it works.

冬天旳寂寞 2024-10-21 07:36:51

我个人不会只使用 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

晨曦÷微暖 2024-10-21 07:36:51

试试这个:

<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>

区别在于 3 个等号而不是 2 个。JavaScript 中的双等号让运行时尝试对要比较的项目进行类型强制,而使用 3 个等号时,它会按原样比较它们。

然而,正如上面的评论者所指出的,使用 javascript 作为唯一的密码保护充其量是天真的。

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.

However, as the commenter above noted, using javascript as your only password protection is naive at best.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文