0

I'm looking for the solution on how to make my popup window depend on a screen resolution. I'm using javascript, since this is a requirement.

My pop up window opens when the following function is called:

function openContent("mypage.htm);

I was trying to figure it out and have the following:

function openContent(url) {

    var width = 900;
    var height = 900;
    var left = screen.width/4;
    var top = 0;
    var win;

    alert("Screen Height: " + screen.height);
    alert("Screen Width: " + screen.width);

    if (screen.width < 900) {
        width = screen.width - 100;
        left = screen.width - width ;
    }


    if (screen.height <= 900) {
        height = screen.height - 70;
        width = width - 100;
    }


    win = window.open(url, 'content', "toolbar=no, titlebar=no, status=no, scrollbars=yes, resizable=no, top=" + top + ", left=" + left + ", width=" + width + ", height=" + height + "\"");
    win.focus();
}

I have two desktops at my work place. When trying with different resolution, this page sometimes is split between 2 desktops.

Also, some part of a window is hidden when its height is greater than screen's height. I'm also thinking about laptop users. Will they be able to see the whole page as well

What is a good solution to that?

Thank you

Hawk
  • 788
  • 1
  • 6
  • 18
eugene.it
  • 417
  • 3
  • 13
  • 32

2 Answers2

0

I believe this answer will help you even though it's originally covering another aspect:

https://stackoverflow.com/a/16861050/2479028

Community
  • 1
  • 1
Ramy Nasr
  • 2,367
  • 20
  • 24
0

No need so many code, just do the one below:

alert("Text here");

A pop-up window will show up.

Tell me if you need help.