问题描述
我正在开发纯粹使用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?
推荐答案
一般规则是弹出窗口阻止程序会在窗口时启用。从直接用户操作未调用的javascript调用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.
这篇关于避免浏览器弹出窗口阻止程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!