Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What possible uses are there for: onresize="window.location.reload(false);"?

I ran across this code in some HTML and I am unsure what the point of it is:

onresize="window.location.reload(false);"

I am not very proficient in JavaScript, but it looks like it basically just... reloads the browser window when it is resized? Does that even work? It seems odd.

like image 491
pzkpfw Avatar asked Jan 24 '26 20:01

pzkpfw


2 Answers

It does reload the page as you suspect, although the argument false that is passed to reload indicates that the page should be reloaded from the cache if possible, to minimize load time. See Mozilla's window.location documentation for more details.

I suspect this is to force the browser to re-layout the page in case resizing the window changes how it renders. Typically that should not be necessary, especially if the site is employing responsive web design techniques, but some sites may do it anyway.

like image 174
Stuart M Avatar answered Jan 27 '26 08:01

Stuart M


I agree with Stuart. Do you own this code? In other words can you make changes to the code and deploy it to some test environment? If so, try commenting that line and see what happens. May be this line was added way back when some particular browser couldn't handle window re-size events correctly. May be it's not needed anymore.

like image 45
Gautam Tandon Avatar answered Jan 27 '26 10:01

Gautam Tandon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!