See also: JSV_getWindowDeltas, JSV_getWindowDimensions, JSV_xyValues

Centers the designated browser window on the screen.

Syntax

JSV_centerWindow(expX, expY | expXY)

Returns

Returns an x,y object (see JSV_xyValues) containing the distance from the left of the screen (x value) and distance from the top of the screen (y value) to place the window.

Parameters

The JSV_centerWindow function uses the following arguments.

Argument Description
expXY The x,y object (see JSV_xyValues) that contains the width and height, respectively, of the window to be centered.
expX, expY The width (expX) and height (expY) of the window to be centered.

Remarks

This function is for use with browsers that support JavaScript 1.2 or later.

For more information on centering a browser window on the screen, see JavaScript Vision Frequently Asked Questions.

Dependencies

n/a

Example

The following lines of code

var myWindowHandle = null;
var myWindow = "JSV_Test";
var myAttributes =  'status=1,scrollbars=1,resizable=1,' +
                    'width=580,height=240,' +
                    'left=40,top=40,screenX=40,screenY=40';

var myXY = new JSV_xyValues(580,240);
var jsvWindowDeltas = new JSV_xyValues();

function windowTest() {
    myWindowHandle = JSV_popWindow( myWindowHandle, 
                                    myWindow, 
                                    'JSV_TestWindow.html', 
                                    myAttributes, 
                                    false);
    jsvWindowDeltas = JSV_getWindowDeltas(myXY, myWindowHandle);
    var centerTopLeft = JSV_windowCenter(myXY);
    myWindowHandle.moveTo(centerTopLeft.x, centerTopLeft.y);
}

function windowTest2() {
    var windDimensions = JSV_getWindowDimensions(myWindowHandle, jsvWindowDeltas);
    var centerTopLeft = JSV_windowCenter(windDimensions);
    myWindowHandle.moveTo(centerTopLeft.x, centerTopLeft.y);
    myWindowHandle.focus();
}

produce



Window Center Test:

  1. Click the Window Center (Part 1) button to open the test window.
  2. Manually resize the window and move it to a different part of the screen.
  3. Click the Window Center (Part 2) button to center the window, that you resized, on the center of the screen.