473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 15122
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

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

Similar topics

4
by: troloo | last post by:
Hello, I hope you can help me :)) The story goes as follows: I have a class with different methods and member variables. I store pointers to objects of this class inside a vector. Now, I would like...
6
by: David Hayes | last post by:
juglesh <juglesh@nospamRadioKDUG.com> wrote in "Re: how to maximize the browser window that fits the monitor size?" (Saturday, January 01, 2005 3:12 AM): > > >I want to maximize the browser...
6
by: rob | last post by:
Hi I'm trying to create a "roll-up" effect when a window loses focus and then "roll-down" when it regains focus. This statement works properly with every browser I can get my hands on EXCEPT...
5
by: laredotornado | last post by:
Hello, When the user resizes the browser (either by clicking on the lower right or clicking the button at the upper left to maximize screen dimensions or not), how do I catch that event and then...
2
by: Dmitri Shvetsov | last post by:
Hi, I'm using these strings around DataGrid <div ID="div1" style="LEFT: 4px; OVERFLOW: auto; WIDTH: 100%; POSITION: absolute; TOP: 248px; HEIGHT: 300px"> ....datagrid... </div>
0
by: khurram.shakir | last post by:
I am developing an application, which uses .NET 2.0/WinForms and has a designer for screen layout designing. User has an option to design the layout of screen, and for that we developed our own...
7
by: Delme Greening | last post by:
I have an empty project with a button on a form. What code do I need to put behind the button to draw a rectangle on my form when it is clicked?
1
by: spamfilteraccount | last post by:
Hi, I want to make a really simple form with C# and windows forms, which is trivial with Java, but I'm unable to reproduce it with .NET. I can't believe it's impossible. I want a simple...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.