Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh page on resize with javascript or jquery [duplicate]

Tags:

I want to force the browser to refresh the page when the user resizes it. I have following code:

function refresh() { location.reload(); }  <body onResize="refresh()"> 

but it does not work. Does anyone of you has a solution? Thanks

like image 483
supersize Avatar asked Feb 16 '13 22:02

supersize


2 Answers

Do it with javascript/jquery:

just javascript:

window.onresize = function(){ location.reload(); } 

with jquery:

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

or

$(window).on('resize',function(){location.reload();}); 
like image 50
Phillip Schmidt Avatar answered Oct 01 '22 08:10

Phillip Schmidt


The following code seems to work with all browsers,

$(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 */   }, 100); }); 

Hope it helps everyone. I found this information here: http://www.jquery4u.com/snippets/jquery-refresh-page-browser-resize/

like image 32
JCBrown Avatar answered Oct 01 '22 08:10

JCBrown