Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A little javascript help

Status
Not open for further replies.

Gxp

Technical User
Nov 24, 2004
6
CA
I have a little problems and was wondering anyone can help.

In my xml page:
onload="new_page('&base.uri;'), window_size();">

in my javascript file:

function window_size() {
height = screen.availHeight - 25;
width = screen.availWidth - 10;
//dump("*** WINDOW SIZE IS " + height + " : " + width + "***\n");
window.resizeTo(width, height);
}

I have this page is currently set at 800x600 resolution, smaller than the desktop resolution of 1024x768. What I want is to make the page load dead in center center and not floating at top left as it currently is.

I experimentt with the window.moveBy and window.moveTo() function but these are only relative guess and not auto-detect to dead center, doesn't matter what resolution i'm currently running. I'm thinking there must be some kind of javascript arithmetic that let you do this, but haven't found a solution to do so. Does anyone have epxerience in this before and have a solutions? I would be very appreciated.

Thank you.
 
There is no single function, but you can try this:
Code:
function centerWindow()
{
  var h = screen.availHeight, w = screen.availWidth;
  var diffh = screen.height - h, var diffw = screen.width - w;
  var left = diffw / 2, top = diffh / 2;
  window.moveTo(left, top);
}

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
You're welcome.

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top