1

I am having the following javascript which open ups a child window with the sizes and align it int he center of the screen

function PopupCenter(url, title, w, h) {
            // Fixes dual-screen position                         Most browsers      Firefox
            var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
            var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

            var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
            var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

            var left = ((width / 2) - (w / 2)) + dualScreenLeft;
            var top = ((height / 2) - (h / 2)) + dualScreenTop;
            var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

            // Puts focus on the newWindow
            if (window.focus) {
                newWindow.focus();
            }

            var timer = setInterval(checkChild, 500);
                function checkChild() {
                    if (newWindow.closed) {
                        var message = 'You have aborted the transaction by closing the window !';
                        var status = 'closed';
                        paymentResponseDisplay(message,status)   
                        clearInterval(timer);
                    }
            }
            window.onbeforeunload = function() {
                if(!newWindow.closed){
                    return "Do you really want to abort this transaction?";
                }
            }

        }    

But in safari I am getting

TypeError: undefined is not an object (evaluating 'newWindow.focus')

I am unable to find a fix for this. Can some one help out?

Ajeesh
  • 5,650
  • 8
  • 30
  • 52
  • I don't think I can, but did you test your newWindow var via console? Did you test with a simple window with minimal parameters? See if that makes a difference – yezzz May 07 '16 at 21:25
  • tried still the same – Ajeesh May 07 '16 at 21:25
  • it may actually fail due to browser restriction: https://developer.mozilla.org/en-US/docs/Web/API/Window/focus – yezzz May 07 '16 at 21:38

1 Answers1

0

In my case, this problem occurred because I called popup from the ajax result in the Safari. I received ajax with sync and it worked fine.

window.open() works different on AJAX success

Community
  • 1
  • 1
Yeongjun Kim
  • 739
  • 7
  • 19