Center xul dialog on screen

In the dialog I resize some of the images and then force the window to fit the ToContent. Then I want the dialog to be centered on the screen. How can i do this?

+2


source to share


3 answers


The end result is a window that moves by itself? Please don't make it too annoying :)

In any case, you will need to do it manually using window.moveTo

and various properties screen

(see https://developer.mozilla.org/en/DOM/window )



Here's an interesting example, although it does not center the window, it makes it visible: http://www.koders.com/javascript/fid3F51B87DFD457428278627805CCA8D39ADC13455.aspx?s=window#L3

+1


source


I also searched around and looked at the MDC for anything to center it, but couldn't find anything, so I created this! This will work both in the window and in the dialog.

var w=(screen.availWidth/2)-(document.getElementById('windowID').width/2);

var h=(screen.availHeight/2)-(document.getElementById('windowID').height/2);

window.moveTo(w,h);

      



The only thing you have to change is windowID

to your window id value. It will work on all screen resolutions as it takes the total screen width and height and then divides it in half, thereby giving the center of the screen, and then subtracts your width and height settings to account for them, but halves them and compensates for the window without offset will not be centered.

Hope this helped!

+2


source


Element

A <dialog>

defines the convenience methods moveToAlertPosition () and centerWindowOnScreen () for you, and also copies them to the global scope, so you don't need to combine them with document.documentElement.

+1


source







All Articles