【问题标题】:want to bypass a popup on page load containing only webaddress想要绕过仅包含网址的页面加载弹出窗口
【发布时间】:2019-10-31 20:54:40
【问题描述】:

在我的一个网站中,我希望在页面加载时出现一个弹出窗口,并且此弹出窗口不得被弹出窗口阻止程序阻止

我已经尝试过 location.href

<html>
<head>
<script>
function aaa()
{
var href= "http://digiskills.pk";

popup = window.open('http://digiskills.pk', 'width=400 height=400');


	if (popup === null || typeof popup === "undefined")
		{
			location.href = href;

		} 
	else 
		{
			popup.focus();

		}
}



</script>
</head>
<body onload=aaa()>
</body>
</html>

上面的代码只是通过而不是在弹出的URL中打开

【问题讨论】:

  • 我认为您误解了弹出窗口阻止程序的意义......它阻止......弹出窗口......没有一种简单的方法可以绕过弹出窗口阻止程序。如果你真的必须在用户面前推一些东西,那么在屏幕中间创建一个绝对定位的 div 并且只在你想要的时候显示它..
  • 感谢回复
  • Location href 适用于您所在的页面,而不是弹出窗口。也许看看模式而不是弹出窗口。

标签: javascript html


【解决方案1】:

现代浏览器几乎总是会阻止加载弹出窗口。这些拦截器非常难以规避,这样做可能一开始就不应该成为您的目标。如果您绝对必须有一个弹出窗口,您可以在用户采取行动后打开一个。在大多数情况下,弹出窗口阻止程序不会阻止由于用户操作(例如点击或击键)而直接打开的弹出窗口。

How do I prevent Google Chrome from blocking my popup?

您还需要添加一个窗口名称作为第二个参数,否则您传递的宽度和高度将被解释为新窗口的名称。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Popup Test</title>
  <script>
    // Won't work in Stackoverflow due to security precautions, copy to a html file to test it out
    function pop() {
      let popup = window.open('http://digiskills.pk', 'Digiskills', 'width=400,height=400');
    }
  </script>
</head>
<body>
  <button onclick="pop()">Click me</button>
</body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 2018-06-03
    相关资源
    最近更新 更多