开发者

My Javascript code does not work in IE but works fine in other browsers

开发者 https://www.devze.com 2023-02-07 02:44 出处:网络
I used th开发者_StackOverflow社区e following Javascript to password protect my webpage but it\'s not working for IE, although it works fine for Chrome and Firefox.

I used th开发者_StackOverflow社区e 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!


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号