Zach Shallbetter
Zach Shallbetter

Reputation: 1911

Prevent window.open from refreshing parent window

When I call window.open the parent window refreshes. I haven't seen anything about how to prevent this from occurring. Any help would be appreciated.

left = Number((screen.width/2)-(730/2)),
top = Number((screen.height/2)-(450/2));

var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left;
    window.open('access-modal.html', '', windowFeatures);

win.moveTo(left, top);

Upvotes: 3

Views: 2996

Answers (2)

Zach Shallbetter
Zach Shallbetter

Reputation: 1911

While there were problems with my post after editing. The ultimate solution was preventing the default action.

$('.button').on('click', function(e) {

    e.preventDefault();

        left = Number((screen.width/2)-(730/2)),
        top = Number((screen.height/2)-(450/2));

        var windowFeatures = 'channelmode=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top='+top+',left='+left;
            win = window.open('access-modal.html?env=' + Data.currentOauth + '&url=' + Data.currentAddr, '', windowFeatures);

        win.moveTo(left, top);
        win.focus();

    }

});

Upvotes: 2

John Tolar
John Tolar

Reputation: 357

I am not sure if it is your edit or not.. I know there is an error on win.moveTo(left, top). win is not defined.. the following code is working for me.

<script language="javascript" type="text/javascript">
            function windowOpen() {
                left = Number((screen.width / 2) - (730 / 2)),
                top = Number((screen.height / 2) - (450 / 2));

                var windowFeatures = 'location=0,menubar=0,resizable=0,scrollbars=0,status=0,width=700,height=500,top=' + top + ',left=' + left;
                var win = window.open('access-model.htm', '', windowFeatures);

                win.moveTo(left, top);
            }
        </script>

Upvotes: 1

Related Questions