Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wait for the url to change on click event

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?

like image 428
subhojit777 Avatar asked Nov 25 '25 06:11

subhojit777


1 Answers

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.

like image 110
James Hill Avatar answered Nov 27 '25 18:11

James Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!