How to detect if URL has changed after hash in JavaScript

0 votes
How can I check if a URL has changed in JavaScript? For example, websites like GitHub, which use AJAX, will append page information after a # symbol to create a unique URL without reloading the page. What is the best way to detect if this URL changes?
Jun 18, 2020 in Java-Script by kartik
• 37,510 points
4,407 views

1 answer to this question.

0 votes

Hello @kartik,

Use this code

window.onhashchange = function() { 
     //code  
}

with jQuery

$(window).bind('hashchange', function() {
     //code
});

Thank You!!

answered Jun 18, 2020 by Niroj
• 82,880 points

Related Questions In Java-Script

0 votes
1 answer

How to check if a specific key is present in a hash or not?

Hello @kartik, While Hash#has_key? gets the job done, as it has ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,880 points
3,039 views
0 votes
1 answer

How to open a URL in a new Tab using JavaScript or jQuery?

Hello @kartik, Use window.open(): var win = window.open('http://edureka.co/', '_blank'); if (win) ...READ MORE

answered Aug 25, 2020 in Java-Script by Niroj
• 82,880 points
5,485 views
0 votes
1 answer

How to Determine if page is valid in JavaScript - ASP.NET?

Hello @kartik,  Make the call on an input ...READ MORE

answered Sep 9, 2020 in Java-Script by Niroj
• 82,880 points
2,329 views
0 votes
1 answer

How to get the URL without any parameters in JavaScript?

Hello @kartik, This is possible, but you'll have ...READ MORE

answered Oct 9, 2020 in Java-Script by Niroj
• 82,880 points
5,548 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,913 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,691 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,561 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,897 views
0 votes
1 answer

How to change url after success in ajax without page reload?

Hello @kartik, Use the browser history to change ...READ MORE

answered Apr 29, 2020 in Java-Script by Niroj
• 82,880 points
9,346 views
0 votes
1 answer

How to get the browser to navigate to URL in JavaScript?

Hii, This works in all browsers: window.location.href = '...'; If ...READ MORE

answered May 28, 2020 in Java-Script by Niroj
• 82,880 points
2,396 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP