Refresh page on browser resize

Yuri Boyz
Yuri Boyz used Ask the Experts™
on
I am testing my website. To test the responsive menu I resize the browser and on certain size the mega menu hides and hamburger menu appears. In hamburger menu there is a search keyword textbox and submit button. But it will not work unless I refresh the page.

But if I directly open the website on mobile and tablet then it will work perfectly.

I have added several codes so that if user resize the browser then page reload code will run but thus not works also everytime.

Any solution for this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I wouldn't implement refreshing on browser resize, the only thing it does is annoy viewers.
Are you using Bootstrap for responsiveness? Or some custom JavaScript? It's hard to tell where the problem lies without specific information about the code.
To be honest, the majority of people who resize the browser's window are web designers who want to do a quick responsiveness check. And even if it does work, it does not mean that it will look the same on a mobile device.  The most important thing is that your website works on all kinds of devices when opened directly. It is not that I recommend leaving everything the way it is, it is always worth to get closer to perfection :)
Top Expert 2004
Commented:
>>> the mega menu hides and hamburger menu appears. In hamburger menu
>>> there is a search keyword textbox and submit button. But it will not work
>>> unless I refresh the page.

How are you attaching functionality to the search textbox and submit button?  This sounds like you're directly assign events to elements which are not present as the structure finishes loading.  If that's the case, delegating the events will resolve this issue.

As mentioned above, refreshing the browser after a resize is not a good strategy.  I would tolerate that once before I just found a different site.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
The browser does not notify the web page that the window has been resized.  You would have to be continuously checking the window size to know that.
Top Expert 2004

Commented:
@Dave Baldwin: there's an event for that.  https://developer.mozilla.org/en-US/docs/Web/Events/resize
You should  rethink or fix your template instead.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial