0

Hello I am working in Laravel and I need to open a pop up window and after I close the pop up window, I should make an ajax call. It is working fine in Firefox, but in Chrome it only works the first time but not the second. Here is my code:

<span class="input-group-addon add_btn">
    <a onclick="OpenClassRoomNewTab('#/roomno?iframe=true');" id="dayvisitStudents3" class="btn btn-primary">+</a>
</span>

// JavaScript   
function OpenClassRoomNewTab(url) {
   winchild = window.open(url, '_blank', 'height=500,width=500');
   winchild.onunload = function () {
      var win = winchild.opener;
      if (!winchild.closed) {
          win.roomBind();
      }
   }
}

function roomBind() {
    window.setTimeout(function () {
        if (winchild.closed) {
            $.ajax({
                type: 'post',
                data: '',
                url: '<?php echo url('refreshdropdown'); ?>',
                success: function (responseText) {  
                    if (responseText) { 
                        $('#classRoomArea').empty();
                        $('#classRoomArea').append(responseText.roomno);
                    }
                }   
            }); 
        }
    }, 1);
}

I tried to debug the code and the problem is in this part if (winchild.closed) first time its working but second time condition always false.

Srijan Karki
  • 1,576
  • 2
  • 14
  • 21

1 Answers1

0

I think you should change the way you're thinking. On winchild (the popup), write an unload event, which triggers a method on window.opener.

Here it is answered:

https://stackoverflow.com/a/1777985/916000

Community
  • 1
  • 1
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78