我正在开发一个纯 JavaScript 的 OAuth 身份验证流程,我想在弹出窗口中向用户显示授予访问权限"窗口,但它被阻止了.
I'm developing an OAuth authentication flow purely in JavaScript and I want to show the user the "grant access" window in a popup, but it gets blocked.
如何防止由 window.open
或 window.showModalDialog
创建的弹出窗口被不同浏览器的弹出窗口阻止程序阻止?
How can I prevent pop up windows created by either window.open
or window.showModalDialog
from being blocked by the different browsers' pop-up blockers?
一般规则是,如果 window.open
或类似的内容是从 直接用户操作.也就是说,您可以调用 window.open
来响应按钮单击而不会被弹出窗口阻止程序击中,但是如果您将相同的代码放入计时器事件中,它将被阻止.调用链的深度也是一个因素 - 一些较旧的浏览器只查看直接调用者,较新的浏览器可以回溯一点以查看调用者的调用者是否是鼠标点击等.保持尽可能浅以避免弹出窗口阻止程序.
The general rule is that popup blockers will engage if window.open
or similar is invoked from javascript that is not invoked by direct user action. That is, you can call window.open
in response to a button click without getting hit by the popup blocker, but if you put the same code in a timer event it will be blocked. Depth of call chain is also a factor - some older browsers only look at the immediate caller, newer browsers can backtrack a little to see if the caller's caller was a mouse click etc. Keep it as shallow as you can to avoid the popup blockers.
这篇关于避免浏览器弹出窗口拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!