0

I want to reload the page on browser resize only, I tried the following code it's loading the browser again and again however I am not resizing the browser window.

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

also i tried this code with $(document).ready(function() { }); but not working

Umer bin Siddique
  • 460
  • 1
  • 4
  • 13
  • I think you have opened your console. Please close your console and try once again – Rana Ghosh Feb 20 '17 at 14:55
  • My guess is that the browser is resizing because of the content on the page, specifically when the scroll bar is added after the content becomes too long. Is your JavaScript is at the end of your body so that it loads last? – Michael Coxon Feb 20 '17 at 15:03
  • I would also suggest implementing this so that you don't make your users want to leave: http://stackoverflow.com/questions/2854407/javascript-jquery-window-resize-how-to-fire-after-the-resize-is-completed?rq=1 – Michael Coxon Feb 20 '17 at 15:04
  • 1
    _“I want to reload the page on browser resize only”_ – that sounds like a really really rehaheally bad idea. _Why_ do you want to do that? – CBroe Feb 20 '17 at 15:05
  • i am giving equal height to my elements which changes when browser resize so i want to reload my page when user expand or reduce the window size – Umer bin Siddique Feb 21 '17 at 05:40

2 Answers2

0

try this..

window.addEventListener('resize', function () { 
    "use strict";
    window.location.reload(); 
});
Dee_wab
  • 1,171
  • 1
  • 10
  • 23
  • it helped me 50% my code is `window.addEventListener('resize', function () { "use strict"; window.location.href = window.location.href; });` – Umer bin Siddique Feb 21 '17 at 06:27
0

Your code seems correct. Check if you are triggering the resize event programmatically somewhere in your code like $(window).trigger('resize');. Also if keep in mind that if you have your inspector open and you expand it, that also triggers the window resize event.

Sebas
  • 9
  • 1