1

My objective is to position a new window opened with the window.open() method in the bottom righthand corner of the screen, but setting right=0 and bottom=0 does not work.

Changing width and height makes a difference, but changing top, bottom, right or left still results in the window opening in the top lefthand corner.

Why is this and how would one position the window in the lower right hand corner?

window.open('https://google.com', '_blank', 'location=yes, height=250,width=550, right=0, bottom=0, scrollbars=yes,status=yes');  
iskandarblue
  • 7,208
  • 15
  • 60
  • 130

2 Answers2

5

You need to set the top and left to the inner height and width minus the height and width of your new window.

<script>
    function OpenMe(){
    var height = 250;
    var width = 550;
    var top = window.innerHeight-height;
    var left = window.innerWidth-width;
    window.open(
        'https://google.com', 
        '_blank', 
        'location=yes,height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes,status=yes'
    );
    }
</script>
Community
  • 1
  • 1
Aaron K.
  • 324
  • 1
  • 6
  • 13
  • This solution is not working. That calculated 'left' parameter does not position the window correctly. Here is the JavaScript code that does the job: const left = screen.availLeft + (screen.availWidth - width) / 2; – OrizG Feb 16 '23 at 16:40
4

If opened from a browser window on the main monitor, positioning works just fine. If opened from a browser window on a different monitor then positioning fails. I tested this in Chrome.

Tel
  • 81
  • 4
  • 1
    If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/33187536) – Lord-JulianXLII Nov 20 '22 at 19:38
  • you can find dual monitor fix here https://stackoverflow.com/a/16861050/4896948 – Nuryagdy Mustapayev Jun 04 '23 at 10:48