弹出窗口拦截器验证
如何通过 C# 检查客户端浏览器是否打开了弹出窗口阻止程序?
我尝试打开这样的弹出窗口
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}', 'Cliente', 'toolbar=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=no', '720', '600', 'true'); </script>", url));
,但如果浏览器有弹出窗口阻止程序,我需要打开警报,
我该怎么做?
How can I Check if the client Browser has a popup blocker turned on via C# ?
I tried to open an popup like this
ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}', 'Cliente', 'toolbar=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=no', '720', '600', 'true'); </script>", url));
But i need to open a Alert if the browser have a popup blocker
How can I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:
注意:没有测试它是否编译,但这是一般的想法。
查看其他类似问题
编辑 - 添加测试:
产生:
我没觉得这有什么问题。现在,我的建议是删除
标签,并让 RegisterStarupScript 通过传递
true
作为最后一个参数来添加它们,如下所示:You can do something like this:
Note: Did not test whether it compiles or not, but that's the general idea.
See this other similar question
EDIT - adding test:
Produces:
I don't see anything wrong with that. Now, my suggestion is that you remove the
<script></script>
tags and let RegisterStarupScript add them by passingtrue
as the last parameter as so:我想所有现代浏览器都会阻止不是由用户操作触发的弹出窗口,例如。单击某物。在打开窗口之前您真的需要往返服务器吗?
如果不需要往返,您应该执行以下操作:
I guess all modern browsers would block popups which are not triggered by an action of the user, eg. clicking on something. Do you really need the roundtrip to the server before opening the window?
If the roundtrip is not necessary, you should do something like: