www.webdeveloper.com
Results 1 to 4 of 4

Thread: Position modal dialog box relative to screen

  1. #1
    Join Date
    Sep 2010
    Posts
    13

    Position modal dialog box relative to screen

    I want to position a modal dialog popup on the bottom right corner of the user's monitor. Right now I use these parameters, which work on most regular aspect monitors:

    Code:
    window.showModalDialog("url", "","dialogWidth:400px; dialogHeight:400px; dialogTop:600px; dialogLeft:800px; center:no; status:no")
    But on a widescreen monitor it doesn't go as far right as it should, and I don't want to increase the dialogLeft parameter any more in case someone has a browser that would make the window appear off the screen.

    So I find out the user's screen size, and set two parameters to use as a position, like this:

    Code:
    var x = window.screen.availWidth - 400;
    var y = window.screen.availHeight - 400;
    Now I should be able to put x and y into dialogLeft and dialogTop in the popup code, but they just don't work.

    Is there a syntax for this which I am missing?

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Positions the dialog bottom right corner of the screen
    Code:
    var x = window.screen.availWidth - 400;
    var y = window.screen.availHeight - 400;
    window.showModalDialog("noob.htm", "","dialogWidth:400px; dialogHeight:400px; dialogTop:"+y+"px; dialogLeft:"+x+"px; center:no; status:no")};
    The dialog can not be placed off screen, so you could use huge values for it's position and still it would be placed in the corner of the screen..
    Last edited by Fang; 11-25-2010 at 10:00 AM.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Sep 2010
    Posts
    13

    Position modal dialog

    Thanks, Fang, works perfectly. I nearly had it, didn't have enough + signs.

    Regarding the dialog going off-screen, I noticed that in Chrome you lose about 50px of the bottom of the box if you set it too low.

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Chrome doesn't include the scrollbars or the taskbar.
    Safari doesn't support showModalDialog.
    At least 98% of internet users' DNA is identical to that of chimpanzees

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles