Website: detect when I get somewhere due to history navigation

I have a page where I display a throbber when I navigate far from the page. Like <a onclick="throbber.show()"> for each link. When I now go back to Firefox, it is still displayed.

Is there any javascript event that will be sent to an inbound webpage when I click? Or the one that only starts when the webpage is changed to a new one? Or can I make my pulse smarter?

Thanks for any input!

+4
source share
3 answers

Dldnh told me to do some tests. I suspected that the body.onload () event would be raised when moving back and forth. So I created a simple test page and found out that this is true in Firefox 10, IE7, IE 8, IE 9, and Chrome 17. jQuery (document) .ready () will also be called.

So a very simple solution for hidind throbber will either use

 <body onload="hideThrobber()"> 

or using ready jQuery

 jQuery(document).ready(function () { hideThrobber(); }; 

to hide throbber. I implemented this and it seems to work fine on my page. It would be great if anyone with a similar problem could confirm this.

I also found this fooobar.com/questions/9314 / .... Although this is a bit outdated, the problem is that calling javascript while navigating forward and backward slows down the page still remains true. But I would suggest that today's JS engines are fast enough, so this is no longer a problem.

+1
source

put this in your html:

 <form name="_browser"><input id="checker" value="1" type="hidden"></form> 

as well as this javascript:

 function cacheCheck() { var checker = document.getElementById("checker"); if (checker.value == 2) return true; checker.value = 2; checker.defaultValue = 2; return false; } function cacheReload() { if (cacheCheck()) location.reload(true); } 

and then call cacheReload when the page loads:

 <body onload="cacheReload()"> 
+1
source

If you cannot turn off the ripple from the page you are going to, there are a few things you can do. The trick is to keep the page active, so you can run some things before leaving in onclick. They are not perfect, though.

  • Start the timer. The timer will start when you return to the page, so that the timeout procedure will be called, and you can turn off the pulse there.
    Problem: if you set the timer interval too short, the wait procedure will be called before the user actually leaves the page and the interrupt stops. Or, if you set the interval too long, it will take some time before the timeout procedure starts to work after they return.

  • Add an event listener to the body responding to the mousemove event, so that as soon as the user moves the mouse, a procedure will be called that will disable the probing.
    Problem: if the user clicks the "Back in browser" button, the mouse will be outside the window when the page is redrawn, so the ripple will remain visible until the user moves the mouse to the window.

So, take your pick. Or both. Just remember to clear later - stop the timer, delete the event listener.

0
source

Source: https://habr.com/ru/post/1401786/


All Articles