?
Solved

JQuery to refresh browser when Browser is resized

Posted on 2014-08-01
6
Medium Priority
?
4,199 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

0
Comment
Question by:rgranlund
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40234562
Whats the point of the reload?
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40234575
That would be a good way of doing it, but I'm with Gary, why would you want to do this?
0
 
LVL 17

Expert Comment

by:contactkarthi
ID: 40234577
$(window).resize(function () { location.reload();});
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:rgranlund
ID: 40234596
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?
0
 
LVL 58

Accepted Solution

by:
Gary earned 1400 total points
ID: 40234599
So your window resize binding should be refreshing the cufon not the browser.

$(window).bind('resize', function(e)
{
  if (window.RT) clearTimeout(window.RT);
  window.RT = setTimeout(function()
  {
    Cufon.refresh();
  }, 200);
});

Open in new window

0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 40234638
Oh, that is great, that is exactly what I needed.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question