wait for the url to change on click event

javascript, jquery, window.location

Solution

To retrieve the new hash of the page, use location.hash:

var hash = window.location.hash;

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

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

Here's a working fiddle to demonstrate.

Additional Information

This SO post is worth reading: On - window.location.hash - change?

Note

If you don't want to use a plugin, you'll have to post your markup before I can provide an alternative solution.

Problem

I have an image, on clicking the image the URL changes but the page is not reloaded(partial navigation). I have used `window.location.href` that fetches the current URL, but it displays the previous URL on console log. I want to fetch the URL after it changes. Am I missing some window wait event?

Original source

Related problems