2

How do I listen for a browser back button click and call a function that I've defined and disable the normal behaviour of the back button? I'm using jQuery.

1
  • 2
    it is bad idea to change the normal functionality of the UI elements (like back button). If you are using AJAX to load the pages then it is okay to use History plugin of jQuery. Commented Jan 28, 2011 at 11:03

2 Answers 2

2

jQuery history plugin helps you to support back/forward buttons and bookmarks in your javascript applications. You can store the application state into URL hash and restore the state from it.

Sign up to request clarification or add additional context in comments.

Comments

1

You could play with :

$(window).unload( function () { alert("Bye now!"); } );

.unload()

But this will be trigered when the user clicks a link that goes to another page , types a new address in the address bar or ... basicly it will be trigered whenever the user leaves the current page . I don't think you can stop the user from going away from you're page tough .

UPDATE:

unload() is now deprecated from jquery 1.8

2 Comments

it's not just a page, but a full-blown system, and the content that shows up is being loaded in one div or another with load() function. So the thing is, I have a button put in the system, which reloads the information that was shown before. It's not very intuitive though, and I would like to make the browsers' Back button to call the same event as that button input in the system does. Is it possible?
I don't now for shure , but i don't think any browser will allow you to change the bahaviour of the back button ( or any other button for that matter ) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.