I made a funny hack to solve this problem to my satisfaction. I have an AJAX site that dynamically loads content and then modifies window.location.hash, and I had code to work with $ (document) .ready () to parse the hash and load the corresponding section. The fact is that I was completely satisfied with the loading code for the navigation section, but I wanted to add a way to intercept the browser buttons back and forth, which change the location of the window, but do not interfere with my current page loading routines, where I manipulate window.location, and poll the window . A cell with constant intervals is out of the question.
As a result, I created an object as such:
var pageload = { ignorehashchange: false, loadUrl: function(){ if (pageload.ignorehashchange == false){
Then I added a line to my website script to run the pageload.loadUrl function on hashchange as such:
window.addEventListener("hashchange", pageload.loadUrl, false);
Then, anytime I want to change window.location.hash without starting this procedure to load this page, I simply add the following line before each line of window.location.hash = :
pageload.ignorehashchange = true;
and then the following line after each line of the hash modification:
setTimeout(function(){pageload.ignorehashchange = false;}, 100);
So, now my partition loading procedures usually start, but if the user presses the back or forward buttons, the new location is analyzed and the corresponding section is loaded.
Tom Penzer Feb 23 2018-12-12T00: 00Z
source share