is blocked by popupblocker

I have this code (based on what I could find on the internet about this problem):

  var newwindow = null;
  var btn = $('#btnCED');
  if (btn.length == 0) { 
    btn = document.createElement('button'); = 'btnCED';
    var body = document. getElementsByTagName('body')[0];
    $(document).on('click', '#btnCED', function(e) {
      if (newwindow != null && !newwindows.closed) {
        setTimeout(function() {
          newwindow.location = '';
        }, 1000);
  $(document).ready(function() {
    newwindow ='');
    setTimeout(function() {
    }, 1000);

When the page is ready, the button has been placed and the click event fires. But newwindow remains null because the browser blocks it already.

Almost every post I have read using a variable to store the window and using a button to get a click event is mentioned as the solution.

The line is now in the ready part but I have also tried it when it was inside the click event and inside the settimeout function in the click event.

Then why is this not working??


There are two reasons it isn’t working:

  1. The call is not triggered by a button click. You have that directly in the ready event handler.
  2. Only real button clicks count. Programmatically generated ones don’t. (Allowing programmatic clicks would defeat the object, which is to allow new windows only in response to user interactions).