469,336 Members | 5,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Simple > Refresh on window resize.

jeremydowe
Hi,

I know this may sound unnecessary, but I want to refresh the page anytime the user resize's their browser window.

I have some code which I found that get's the browser's width dimension.

function getBrowserWidth()
{
if (window.innerWidth)
{
return window.innerWidth;
}
else if (document.documentElement && document.documentElement.clientWidth != 0)
{
return document.documentElement.clientWidth;
}
else if (document.body)
{
return document.body.clientWidth;
}

return 0;
};

How can i create a loop to check between say current value and a new value to then see if the browser's window has changed?

Any help, please?

Jez.
Mar 5 '07 #1
7 14813
pronerd
392 Expert 256MB
How can i create a loop to check between say current value and a new value to then see if the browser's window has changed?
Creating the loop is easy. Creating a loop that will not bog down the browser, and trigger the browser to warn the user that their is an out of control loop would be tricky. It would be a good idea to add some delay to this.


function checkWindowSizeLoop() {

// blah blah blah
// your logic to check the window size here

checkWindowSizeLoop();
}


I better option might be to create a global event handler that would check any time it is triggered. This would check every time they moved their mouse in the browser window.


//
// Create event listeners in IE
//
if( document.attachEvent ) {
document.attachEvent("onmousemove", checkWindowSize());
}

//
// Create event listeners in Gecko browsers
//
else if(document.addEventListener) {
document.addEventListener("mousemove", checkWindowSize(), false);
}
Mar 5 '07 #2
So the mouse-listener creates a loop while checking for the mouse move.

I just am not sure where to take it from here?

Jez.
Mar 5 '07 #3
Okay I have a way of getting the window to refresh between certain widths i.e.

if (theWidth > 600 && theWidth < 800)
{
history.go(0);
}else{
}

How do i get the refresh to stop cycling through. Shouldn't it only do it once?

Is there an exit command?

Jez.
Mar 5 '07 #4
sumittyagi
202 Expert 100+
You can use resize event.

<body onresize="myFunction()">
...
...
</body>

or attach that event dynamically

//
// Create event listeners in IE
//
if( document.attachEvent ) {
document.attachEvent("onresize", myFunction());
}

//
// Create event listeners in Gecko browsers
//
else if(document.addEventListener) {
document.addEventListener("resize", myFunction(), false);
}

(here your myFunction() will be called whenever user resizes the window.)
Mar 5 '07 #5
acoder
16,027 Expert Mod 8TB
Yes, read about onresize here.
Mar 5 '07 #6
Yes, read about onresize here.
I found that this works in IE 6.

However in Safari the browser cycles through a reload continuously.

location.hash = location.hash as suggested doesn't work.

http://www.howtocreate.co.uk/safari/...onHashBug.html

thanks for the input.

jez.
Mar 6 '07 #7
i used javascript:history.go(0);

and that is working.
Mar 6 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by troloo | last post: by
6 posts views Thread by David Hayes | last post: by
5 posts views Thread by laredotornado | last post: by
2 posts views Thread by Dmitri Shvetsov | last post: by
7 posts views Thread by Delme Greening | last post: by
1 post views Thread by spamfilteraccount | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.