Forum Moderators: open

Message Too Old, No Replies

Can javascript resize the browser window once everything's loaded?

         

nevdev

10:09 pm on May 25, 2006 (gmt 0)

10+ Year Member



Does anyone know if there is a way of using Javascript (or anything else, for that matter), to resize the browser window (by even as little as 1 pixel), but only when everything in a page has completely loaded?

Thanks for any insight!

nevdev

11:09 pm on May 25, 2006 (gmt 0)

10+ Year Member



Maybe I should add that it would be nice if some code could resize it by a small amount, and then return it to the size it was.. Don't know if this is possible, but if it is I think it would solve a problem.

nevdev

11:41 pm on May 25, 2006 (gmt 0)

10+ Year Member



Oh well I think I got it (this is probably all wrong but it seems to work):

<script type="text/javascript">
window.resizeby( -10, -10 );
</script>
<script type="text/javascript">
window.resizeby( 10, 10 );
</script>

Clemens

11:32 pm on May 26, 2006 (gmt 0)

10+ Year Member



The code is quite right ;)

I might, pull the window.onload on it, in case it should wait till the content was loaded - but there probably shouldn't be any reason to pull up the onload handler, since the window could be resized, before the content is loaded without problems.

<script type="text/javascript">
window.onload=function(){winalign();}

function winalign(){window.resizeBy(10,10);}
</script>

code desc. for newly js interested persons that might drop by:
- window.onload=function(){} waits for the document's content to load - and then executes the script.
- window.resizeBy(x,y) for specifying offset between current width/height and the new width/height.
- window.resizeTo(x,y) not relevant here - but it defines the new width/height of the window.

nevdev

11:09 am on May 27, 2006 (gmt 0)

10+ Year Member



Thanks for that tip - I do really want the script to execute when everything on the page has loaded.. to do this I put the code just before the closing body tag - is that right? Or do I need the window.onload part as well? How would that look? Thanks again!

Clemens

11:55 am on May 27, 2006 (gmt 0)

10+ Year Member



You're welcome :)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=iso-8859-1"><title>No title</title>

<script type="text/javascript">
window.onload=function(){winalign();}
function winalign(){window.resizeBy(10,10);}
</script>

</head>

<body>
Something...
</body></html>

Or:

- make a winalign.js file with this content:
window.onload=function(){winalign();}
function winalign(){window.resizeBy(10,10);}

- And heres the other test file:
... (same top part as in the previous) ...

<script type="text/javascript" src="winalign.js"></script>

</head>

<body>
Something...
</body></html>

Edit: The external script name, doesn't need to be named the same as the function of course ... and could also have some other js functions in it...

Edit #2: You could also place the script section, just before the end of the document...

...
<body>
Something...
<script type="text/javascript">window.resizeBy(10,10);</script>
</body></html>

^ But, if you use this instead of onload handler: The html document would have been read into the browser ... however it might not have been fully rendered - and images might not be loaded yet...

nevdev

3:22 pm on May 27, 2006 (gmt 0)

10+ Year Member



OK.. and if I wanted to move the window inwards then outwards, like I said, then would the external js be:

window.onload=function(){winalign();}
function winalign(){window.resizeBy(-10,-10); window.resizeBy(10,10);}

nevdev

3:30 pm on May 27, 2006 (gmt 0)

10+ Year Member



Odd thing here: this only visibly resizes the window in IE.. it doesn't appear to do it in FF or Safari.. however since I needed it to cure a bug that only appeared in IE, that doesn't matter.. though I wonder why it doesn't visibly do it in the gecko browsers

Clemens

3:40 pm on May 27, 2006 (gmt 0)

10+ Year Member



Resizes fine here in both IE (6.0) and FF (1.5.0.1)
- You might try a timeout to slow down the second resize effect a bit:

function winalign(){
window.resizeBy(-10,-10);
setTimeout("window.resizeBy(10,10);",200);
}

- If that doesn't help the script working in your FF try: (sorry if the menu names doesn't fit exactly ... danish edition of FF here): Functions -> Settings -> The tab "Contents" (globe icon) -> "Advanced javascript" settings buttom -> and check "Allow sites to relocate and resize existing windows"...