简体   繁体   English

使用Internet Explorer 8的prompt()

[英]prompt() with Internet Explorer 8

I am having a hard time figuring out a solution for my problem. 我很难找到问题的解决方案。 Here's a code snippet: 这是一段代码片段:

var ans = prompt("Mot de passe", '');
if (ans != '' && ans != null)
   __doPostBack('__Page', ans);
else
   window.location = "../Erreurs/NotAuthorized.aspx";

This code works really great with Internet Explorer 9. But my client is exclusively working with Internet Explorer 8 so I tested it with ieTester in IE8. 这段代码在Internet Explorer 9中运行得非常好。但是我的客户端专门使用Internet Explorer 8,因此我在IE8中使用ieTester进行了测试。 But the problem is that the prompt doesn't show and it automatically redirect because the input had an empty string (''). 但问题是提示没有显示 ,它会自动重定向,因为输入有一个空字符串('')。

So how do I fix this to work with Internet Explorer 8? 那么如何解决这个问题才能使用Internet Explorer 8?

IE has an setting in Internet Options to allow or deny prompt() . IE在Internet选项中有一个设置允许或拒绝prompt()

IE提示设置
(source: adamhaskell.net ) (来源: adamhaskell.net

By default in IE8, this setting is off. 默认情况下,在IE8中,此设置为关闭。 Consequently, calls to prompt() are ignored and "" is returned by them. 因此,忽略对prompt()调用,并返回""

You shouldn't use prompt() anyway. 你不应该使用prompt() Use a form. 使用表格。

It looks like a security thing specific to IE- 8 for sure, I don't have other versions to test. 它看起来像是IE-8特有的安全性,我没有其他版本可供测试。 Calling prompt() produces a warning about a scripted window asking for information. 调用prompt()会产生有关要求提供信息的脚本窗口的警告。 I can click to allow and after refreshing the page, the prompt box appears as expected. 我可以单击以允许并在刷新页面后,将按预期显示提示框。

If you are going to insist on using prompt() , you will probably have to stipulate that security settings on the target machines are configured to allow it. 如果您要坚持使用prompt() ,则可能必须规定目标计算机上的安全设置已配置为允许它。

Microsoft developer website tells us that "prompt()" is deprecated and now normally blocked for security reasons: "By default, this method is blocked by the information bar in the Internet zone. This helps prevent malicious sites from initiating spoofing attacks. " Microsoft开发人员网站告诉我们,“prompt()”已被弃用,现在通常由于安全原因而被阻止:“默认情况下,此方法被Internet区域中的信息栏阻止。这有助于防止恶意站点发起欺骗攻击。”

See http://msdn.microsoft.com/en-us/library/ms536673.aspx 请参阅http://msdn.microsoft.com/en-us/library/ms536673.aspx

From this report it looks like it's a known bug in IETester? 从这份报告来看,它似乎是IETester中的一个已知错误?

http://www.my-debugbar.com/forum/t294-Javascript-Alerts.html http://www.my-debugbar.com/forum/t294-Javascript-Alerts.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM