-3

in my one website i want a pop up appear on page load and this pop up must not be block by pop up blocker

I have tried 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>

the above code only by pass but not open the URL in pop up

  • 4
    I think you misunderstand the point of a popup blocker... its to block... pop ups... There isn't a simple easy way to bypass pop-up blockers. If you really must shove something in the users face, make an absolutely positioned div in the middle of the screen and only show it when you want to.. – Libra Oct 31 '19 at 21:01
  • Thanks for the reply – Quratulain Ainee Oct 31 '19 at 21:06
  • Location href is for the page you are on, not the popup. maybe look into modals rather than a popup. – Slipoch Nov 01 '19 at 04:07

1 Answers1

0

Onload popups will almost always be blocked by modern browsers. These blockers are extremely hard to circumvent and doing so probably shouldn't be your goal in the first place. If you absolutely must have a popup, you could open one after a user takes an action. Popup blockers will, for the most part, not block popups that are opened as a direct result of user action, such a click or keystroke.

See How do I prevent Google Chrome from blocking my popup?

You will also need to add a window name as the second argument, otherwise the width and height you passed will be interpreted as the name for the new window.

<!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>
Fdebijl
  • 887
  • 5
  • 20