• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Back Button disabling using javascript

 
Ajay Vikas
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please advice me how to disable back button of a window using java script?

Thanks in advance!!!

Regards,
Ajay.
 
stef li
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are two approaches to involve it.
1.
window.open(url);
window.opener.close();

2.
window.location.replace(url);


example:
<a href="#" on*click="window.location.replace('http://www.stefli.com/');">stefli</a>
 
Ajay Vikas
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi stef ,

Thank you for your quick reply it is working.

--
Regards,
Ajay
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1 is really bad and browser security should prevent it
Option 2 will fail with users with JS disabled.

A better option for #2


Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic