Welcome to WebmasterWorld Guest from 35.175.191.168

Forum Moderators: open

Message Too Old, No Replies

can we detect when back button of browser is pressed in javascript

or..can i change the urls in my history

     
9:50 am on Nov 10, 2003 (gmt 0)

New User

10+ Year Member

joined:Nov 10, 2003
posts:5
votes: 0


I want to remove the page or replace the pages ion the history of back
button is that possible.. i'm using javascript

ther is the location.replace("new") property to replace the current page
from history.

but the prob is i'm making a logout page...So after logging out..i
shouldn't c the previous page instead i should see another page showing ur
logged out..

so is there any way thr which i can replace the history urls,.

6:28 am on Nov 11, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


I don't know of a way to do this. Even my online banking, which bend over backwards for security, has settled for a big warning about the the fact that pages I viewed will remain in the browser history until the window is closed.

Just typing that gave me an idea -- maybe you can respond to a Log-IN by opening the site in a new window opened by javascript. Then you can respond to a log-OUT by closing that window (since your script opened it) and voila, the Back Button will not allow anyone to get into a record of the session that just finished.

6:37 am on Nov 11, 2003 (gmt 0)

New User

10+ Year Member

joined:Nov 3, 2003
posts:4
votes: 0


From what I understand, I think you're trying not to cache a page... if thats the case, your could try using the following code placed in the head section of the page...

<meta http-equiv="pragma" content="no-cache">

8:01 am on Nov 11, 2003 (gmt 0)

New User

10+ Year Member

joined:Nov 10, 2003
posts:5
votes: 0


actually i'm new to javascript.....
i had did that method which u said of..closing the existing one..and openeing new for logout.

what i'm doing is something like this...in login page
session.setAttribute("username",user)

nd in logout page
session.setAttribute("username",null)

and in all other pages
if (session.getAttribute("username")!= null)

.by that we can go to back page..but no processing can be done...then iit guides to new page..
but i dono other way..can u help out.

and no..i don't want to use no-cache in meta tag

7:12 pm on Nov 13, 2003 (gmt 0)

New User

10+ Year Member

joined:July 27, 2003
posts:37
votes: 0


Is the log in and session all done in JavaScript?
4:15 am on Nov 15, 2003 (gmt 0)

New User

10+ Year Member

joined:Nov 10, 2003
posts:5
votes: 0


nope the session r created in JSP.

Anyway i figured it out....
thanks for all those whoi tried to help me out.

what i did was .... in the logout page...in javascrcipt i added an extra word to the cookie. of the current document.

something like this

document.cookie="someword"

then in all other pages in the head tag i included

if((document.cookie!= "")&&(document.cookie.indexOf("someword")!=-1 ))
window.open("id of the page u want o direct to", "_top");

now it works fine...even if i click the back button..it doesn't shows the previous pages...it brings back to the page i put in the open option.