Wait for the URL to change in the click event.

I have an image, when I click on the image, the URL changes, but the page does not reload (partial navigation). I used window.location.hrefone that retrieves the current URL, but displays the previous URL in the console log. I want to get the url after changing it.

Am I missing a window wait event?

+3
source share
2 answers

To get a new hash of the page, use location.hash :

var hash = window.location.hash;

For a similar requirement in the past, I used the Ben Alman hashChange plugin . When the plugin is included on the page, you can attach the code to the event hashChange:

$(window).hashchange( function(){
    // Your code here
})

.

: On - window.location.hash - ?

, , .

+7
var hash = window.location.hash;
var loc = window.location.href+hash;
window.location=loc;
0

All Articles