skyork
skyork

Reputation: 7391

How should I do a URL re-direct so that the user cannot use the 'Back' button

I would like to redirect users away from a page such that they cannot use the 'Back' button to return to that page. In addition, I would like to make them stay on that page, unless:

  1. They type something else in the address bar and navigate away, or
  2. They close down the tab/browser.

This probably means that after the redirect clicking on the 'Back' button does nothing or the 'Back' button is simply disabled.

What is the right way to do this across the modern browsers (e.g. IE9+, Chrome, FireFox, etc)?

Upvotes: 2

Views: 988

Answers (5)

Ganesh Rathinavel
Ganesh Rathinavel

Reputation: 1335

<SCRIPT LANGUAGE="JavaScript">
function goNewWin() {
window.open("backbuttonnewpage.html",'TheNewpop','toolbar=1,
location=1,directories=1,status=1,menubar=1,
scrollbars=1,resizable=1');
self.close()
}
</SCRIPT>
<A HREF="javascript:goNewWin()">Click to go to a new page</A>

Upvotes: 0

Davor Zubak
Davor Zubak

Reputation: 4746

You can imitate disabling back button on your page. Here are three ways you can achieve this. Take a look here.

Upvotes: 1

Moshe Shaham
Moshe Shaham

Reputation: 15984

the best idea i have is to use ajax to load new content in the window :

$('body').load('/newpage.html')

I don't think there is a way to make the browser disable the back button... also, they can also navigate using bookmarks.

Another thing you can do is open a new window that doesn't have the address bar. If you ok with opening a new window, this might be the best option

Upvotes: 1

bugwheels94
bugwheels94

Reputation: 31920

This behavior woud be very annoying however if you want to do it then use hash values like

<script>
window.onhashchange=function(){
window.location.hash='a';
}
window.onload=function(){
window.location.hash='a';
}

</script>

Upvotes: 1

Ashwin Singh
Ashwin Singh

Reputation: 7355

I think the best way would be to use AJAX, you can also use no-cache attributes which tell the browser to store no pages in cache, which mean there won't be any back button functionality as there would be no history.

Anyways, there are ways of course,

  1. Open all links in new tab, window.
  2. Use ajax.
  3. Use no-cache attributes.

Upvotes: 2

Related Questions