【发布时间】:2019-03-26 14:08:03
【问题描述】:
对于 web 应用,我可以选择打开一个弹出窗口 (w = window.open) 为最终用户启用多屏。
当弹窗在没有用户输入的情况下被 js 打开时(加载之前的用户配置),Firefox 会按预期阻止它。
我可以用w == null 检测到它,如果用户不想要它们,我可以处理它以拥有一个没有弹出窗口的功能性应用程序。
但是,如果用户单击“允许此站点打开弹出窗口”,则 Firefox 会打开一个包含当前页面的弹出窗口。
是否有可能阻止 Firefox 打开被阻止的弹出窗口?
编辑:MWE
<html>
<body>
<script type="text/javascript">
function bug () {
let w = window.open('', '', 'width=800, height=600');
if (w == null) {
console.log("blocked");
return;
}
let p = w.document.createElement('div');
p.className += "layout";
let c = w.document.createElement('div');
c.className += "content";
c.style.height = '100%';
c.innerHTML = "Hello world !";
w.document.body.appendChild(p);
p.appendChild(c);
}
document.body.innerHTML = "Hello fellow human beings";
bug();
</script>
</body>
</html>
Edit2 :当前页面和弹出窗口的混合在我这边,主要问题仍然存在。
谢谢
【问题讨论】:
-
请访问help center,使用tour查看内容和How to Ask。做一些研究,搜索关于SO的相关主题;如果您遇到困难,请发布您的尝试minimal reproducible example,并注明输入和预期输出。
-
您可能会以某种方式使用 window.open 来获得该结果。请发布您的代码。
标签: javascript firefox popup