gpt4 book ai didi

javascript - 如何测试命名窗口是否打开或被弹出窗口阻止程序阻止?

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:26 24 4
gpt4 key购买 nike

我正在使用以下代码在 javascript 中打开一个窗口(实际上是 PayPal):

win = window.open('', this.name, 'top=' + top + ', left=' + left + 
', width=' + width + ', height=' + height +
', location=0, status=0, toolbar=0, menubar=0, resizable=0, scrollbars=1');

如果 Chrome 的弹出窗口阻止程序停止创建窗口,我希望能够检测到并提醒用户。我可以在 win 上运行某种测试来查看它是否真的打开过吗?

最佳答案

Window.open() 中所述:

How can I tell when my window was blocked by a popup blocker?

With the built-in popup blockers of Mozilla/Firefox and Internet Explorer 6 SP2, you have to check the return value of window.open(): it will be null if the window wasn't allowed to open. However, for most other popup blockers, there is no reliable way.

因此,如果 window.open 的返回值为 null 或 undefined 这意味着窗口被阻止。

关于javascript - 如何测试命名窗口是否打开或被弹出窗口阻止程序阻止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38686849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com