How to Intercept call to the back button in my AJAX application

0 votes
I have an AJAX app and when a user clicks a button,the page's display changes. They click the back button, expecting to go to the original state, but instead, they go to the previous page in their browser.

How can I intercept and re-assign the back button event?
Jun 18, 2020 in Java-Script by kartik
• 37,520 points
4,727 views

1 answer to this question.

0 votes

Hello @kartik,

It is very easy toi disable the browser BACK button, like the JQuery code below:

// History API 
if( window.history && window.history.pushState ){

  history.pushState( "nohb", null, "" );
  $(window).on( "popstate", function(event){
    if( !event.originalEvent.state ){
      history.pushState( "nohb", null, "" );
      return;
    }
  });
}

Hope this is helpful!!
Thank You!!

answered Jun 18, 2020 by Niroj
• 82,840 points
Thanks.

It was good for me.

Hey @There,

If the above-given answer has helped you to overcome your query then do UPVOTE the answer and post any of your tech queries with us in the Edureka community!!!

Happy Learning!!!

Related Questions In Java-Script

0 votes
1 answer

How to manage a redirect request after a jQuery Ajax call?

Hii kartik, You can resolved this issue like ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
29,037 views
0 votes
1 answer

How to call jQuery UI Dialog with ASP.NET button postback?

Hello @kartik, To solve the problem with ASP:Button ...READ MORE

answered Apr 28, 2020 in Java-Script by Niroj
• 82,840 points
3,634 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,840 points
9,855 views
0 votes
1 answer

How to do API call in react js?

Hello, Use fetch method inside componentDidMount to update state: componentDidMount(){ fetch('https://dey.me/api/') ...READ MORE

answered May 18, 2020 in Java-Script by Niroj
• 82,840 points
2,183 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,520 points
935 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 1,145 views
0 votes
1 answer

What is data binding in AngularJS?

Data binding is synchronization of data between the ...READ MORE

answered Jan 23, 2020 in Web Development by Niroj
• 82,840 points
1,121 views
0 votes
1 answer

How can we detect timeout on an AJAX (XmlHttpRequest) call in the browser?

Hii, In order to handle a timeout: var xmlHttp ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
5,712 views
0 votes
1 answer

How to trigger an ajax request when the user has finished typing in a text box?

Hello @kartik, Use the code below: //setup before functions var ...READ MORE

answered Sep 18, 2020 in Java-Script by Niroj
• 82,840 points
8,519 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