For example, if an user is on http://example.com, then the user goes to http://example.com#comments. If the user clicks "back" on his browser, how can I make him "ignore" http://example.com and go directly to the URL that he visited before that?
I have jQuery loaded.
You can-not actually disable the browser back button. However, you can do magic using your logic to prevent the user from navigating back which will create an impression like it is disabled.
function disableBackButton() { window. history. forward(); } setTimeout("disableBackButton()", 0);
To disable the browser "Back" button for a specific page: Open the "UI" tab of the page description window ( "Description" option in the page popup menu). In the "Options" area, for the option "Browser "Back" button", select "Forbidden".
function preventBack() { window. history. forward(); } setTimeout("preventBack()", 0); window.
Instead of having a link like:
<a href='#comments'>Link</a>
Use location.replace()
to "overwrite" the record of http://example.com
in the browser's history.
https://developer.mozilla.org/en/DOM/window.location
Example:
HTML:
<a id='commentsLink'>Link</a>
JavaScript:
$("#commentsLink").click(function(){
window.location.replace("#comments");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With