Dual monitor setup for window.open using JavaScript in AsP.Net

Last Reply on Sep 21, 2017 03:20 AM By anvina

Posted on Sep 18, 2017 12:12 AM

 

 //code for pop up
        var popupWindow = null;
        function popup(url, width, height) {
           
            var left = (screen.width - width) / 2;
            var top = (screen.height - height) / 2;
            var params = 'width=' + width + ', height=' + height;

            params += ', top=' + top + ', left=' + left;
            params += ', directories=no';
            params += ', location=no';
            params += ', menubar=no';
            params += ', resizable=no';
            params += ', scrollbars=no';
            params += ', status=no';
            params += ', toolbar=no';

            popupWindow = window.open(url, '', params);
            popupWindow.focus();

            LoadModalDiv();
            if (window.focus) { popupWindow.focus() }
            return false;
        }

 

  Protected Sub GridViewExtensions_RowCommand(sender As Object, e As GridViewCommandEventArgs)


                ClientScript.RegisterStartupScript(Me.GetType(), "YourPopScript", "popup('EditDialog.aspx',500,375);", True)

end sub

In the above code I am opening a aspx page with pop up using window.open.

 

Issue is when using dual monitor set up .

If  i extend my laptop display and start using the website on my second screen and try opening the pop up the pop up opens in my laptop andnot the second screen where te parent page (website) is.

 

How can i make window.open the aspx page pop up in the monitor where the parent page is


Posted on Sep 21, 2017 03:18 AM

HI anvina,

You can't detect if the user has multiple screens using JavaScript.

You could guess it though, if the users screen.width is wider than the screen.height * 1,78 which is more than a 16:9 screen, they probably have two screens beside each other.

This is not reliable at all tough and it will only work if the screens are position beside each other and no screens are positioned above or below.

Here's another thread about finding out if the user has multiple sceens.

http://stackoverflow.com/questions/140462/testing-for-multiple-screens-with-javascript