We help IT Professionals succeed at work.

JQuery to refresh browser when Browser is resized

Robert Granlund
on
6,705 Views
Last Modified: 2014-08-01
I found the following function that will refresh my browser when the browser is resized.  Is this the best way to do it or is there a better code that works cross browser?

/refresh page on browser resize
$(window).bind('resize', function(e)
{
  if (window.RT) clearTimeout(window.RT);
  window.RT = setTimeout(function()
  {
    this.location.reload(false); /* false to get page from cache */
  }, 200);
});

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014

Commented:
Whats the point of the reload?
That would be a good way of doing it, but I'm with Gary, why would you want to do this?
CERTIFIED EXPERT

Commented:
$(window).resize(function () { location.reload();});

Author

Commented:
On the pages of my site, I'm using Cufon.js Font replacement.  When I size down my screen for a responsive design the page needs to reload for the new CSS at specific break points.  There are different font sizes at different browser sizes.  Without the page refreshing the design does not "Snap" into the new css parameters.

Is there a better way to do this?

In addition to this question, If I have a form on a page, is there a way to keep the form from re-submitting if the page refreshes?
CERTIFIED EXPERT
Expert of the Year 2014
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Oh, that is great, that is exactly what I needed.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.