Forum Moderators: open

Message Too Old, No Replies

Open Browser Window at certain size and position

         

jlmetzger

6:20 pm on Apr 20, 2004 (gmt 0)

10+ Year Member



The message below was used to add a Javascript to open a browser window at a certain height and width in the upper right hand corner of the screen. The issue I am having is that from then on, all browsers initially open at this size and position. Is there a quick add to this script to make it erase the settings after the initial launch, so subsequent browser window openings are at full screen? Thanks in advance for your help.

Unfortunately, the destination position of a Javascript moveTo is defined from the top left and no other way. But you can add JS to retrieve the screen size, and then calculate what the margin would be from the top left instead of the top right.

There are several related JS variables about whose vintage I do not venture a guess:

screen.width and screen.height-- simply the width and height of the screen in pixels
screen.availWidth and screen.availHeight-- width/height of the screen in pixels minus "fixtures" like the Windows or MS Office taskbars

Borrowing then from [rtfm.atrax.co.uk...] (I'm actually rather far from a JS expert-- we try not to use it)

<script type="text/javascript">
function start() {

// retrieve user's available screen resolution
w = window.screen.availWidth;
h = window.screen.availHeight;

// resize window according to space available, up to 750x350 if possible

resizedW = (w >= 750)? 750 : w;
resizedH = (h >= 350)? 350 : h;

window.resizeTo(resizedW,resizedH);

// to align the window to the right, subtract its
// width from the available space to find the x value of
// the left margin; set y to zero for top

var x = (w - resizedW);
var y = 0;
window.moveTo(x,y);
}
</script>
<body onLoad="start();">

[edited by: tedster at 7:45 pm (utc) on April 20, 2004]
[edit reason] make link active [/edit]

isitreal

8:55 pm on Apr 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are resizing the browser window, not a pop up, that's not a good idea, you should probably not do that, many users find that extremely annoying. When a browser closes it writes its closing size to the registry in windows, and opens using that size.

Usually you want to open up a second, popup style window when you want a custom sized window, that doesn't create that problem, since the original opener window remains the standard size.

jlmetzger

2:33 pm on Apr 21, 2004 (gmt 0)

10+ Year Member



Thanks isitreal. I know it is a bad idea, but it is for work and there is no other way. I have no control over the call for this page. I am trying to manage some instructions over on the right side of the screen that pop up, but I have no control on the call, so I cannot just use a script on the link that launches this window. I am stuck with having to try to solve it this way.

Is there a line (or 50) that I could add to reset the saved settings so that it only does this once, instead of from then on? Thanks for the help.

isitreal

2:55 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could try this:

<body onunload="window.resizeTo(w,h);window.moveTo(0,0);">

this would at least sometimes return the browser to the settings you got from the screen measurements, although whether this would happen fast enough on window closing to get into the window registry is something you'd have to test.