hi

i have developed simple webapplication using JSP and JSF framework

Step 1 : I have one login page : (contains username ,password and sumbit
button)

Step2 : I have one logout page : it has one link (Go to login page), just
u click this link go to login page..

step3 : And i have some pages like (page1,page2,page3, page4.....)

Normal application working following way :

after login comes page1..
Then click some action and it will go to page2
Then i click some action and it will goto page3
Then i click some action and it will goto page4

So now i am in page4...
now click back arrow in navigation toolbar in
browser, generally go to previous page (page3).

For example... If u seeing gmail inbox msg... that time
u click back arrow..then automatically go to previous
page..

But i need ,
if click back arrow in navigation toolbar
(from any page in my application) ,then
go to logout page...

For example.... Suppose i am in page4... here i click backarrow
in browser then i want to go logout page, don't go to page3

how to acheive this...
Is there any possible....
Any javascript or anyotherway...

Pls help me about this...
i hope anyone help about this task...

Recommended Answers

All 11 Replies

The back arrow navigates the history object which AFAIK can't be changed.
However, you may be able to manage it as follows:
after login create a history entry for the logout page [by loading it without displaying anything and then loading page1 using location.replace]
navigate within the site using nothing but location.replace [which creates no history entries]
With that strategy, back() should always go to the logout page [which must recognize that is to display this time and not load page1]

On further thought the "after login" step is not necessary. The login page just needs to load page1 the first time through and load the logout page any time thereafter.

On the assumption that the page flow is always
login
page1
page2
page3
it turns out that a trivial test of history.length at onload time can trigger a location.replace to logout.

give any reference link, otherwise please give a sample code...

The back arrow navigates the history object which AFAIK can't be changed.
However, you may be able to manage it as follows:
after login create a history entry for the logout page [by loading it without displaying anything and then loading page1 using location.replace]
navigate within the site using nothing but location.replace [which creates no history entries]
With that strategy, back() should always go to the logout page [which must recognize that is to display this time and not load page1]

Suppose i have 10 to 15 pages after login...
you mean ,
so each and very page visit, before i create history for the logout page ?
Otherwise only one time create history for logout page during login page ,is it enough?
i, can't clear...
i am new one, that why ask..

How to add logout page into the browser history...
help me...

But my original requirement :

I have developed secured application using JSF framework.

And also i use scope (session scope)

In my application i use this following code ... but not work it...

public class LogoutPhaseListener implements PhaseListener {

public void afterPhase(PhaseEvent event) { }

public void beforePhase(PhaseEvent event)
{
      FacesContext facesContext = event.getFacesContext();
      HttpServletResponse httpServletResponse = (HttpServletResponse)    
                                               facesContext.getExternalContext().getResponse();
      httpServletResponse.addHeader("Pragma", "no-cache");
      httpServletResponse.addHeader("Cache-Control", "no-cache");
      httpServletResponse.addHeader("Cache-Control", "must-revalidate");
      httpServletResponse.addHeader("Expires", "Mon, 8 Aug 2006  
                                                                                                    10:00:00 GMT");
      httpServletResponse.addHeader("Cache-Control", "no-store");
}

public PhaseId getPhaseId()
{
      return PhaseId.RENDER_RESPONSE;
}
}

If i click back button in browser, then it go to previous page...

but i want to go logout page..when i click back button in browser

http://stackoverflow.com/questions/2627155

i have take lot of effort this...but i can't achieve this...can u help me...any sample code or reference?

give any reference link, otherwise please give a sample code...

First, let me make one point as clearly as I can: no one who uses your site is going to expect BACK to do what you are going to make it do. This will be an annoyance at the very least - more likely it will be widely considered a problem, possibly even a serious one.

Also - and obviously - anyone who has javascript disabled will not get this effect.

With those understandings, here is a basic strategy:
1. include this

<script type="text/javascript">
	if (window.name=='logout')window.location.replace('logout.htm');
	window.name='logout';
    </script>

within the <head> of your login page [this logic uses window.name as a toggle to recognize when control returns to this page]
2. in the body of your login page, the link to the first 'regular' page of your site must be a normal <a href="pagexx.htm">go to pagexx</a> link.
3. EXCEPT for that ONE link, ALL other links within your site MUST use the onclick="window.location.replace('page##.htm')" event [this will prevent entries from being added to window.history after the first, so the entry for your login page will always remain at history(-1)]
3. now, whenever the BACK button (or equivalent javascript operation) occurs [which goes to history(-1)], the login page will be loaded [and the test described in item 1 will immediately pass control to the logout page]

Thanks for your response!
Not perfectly worked..
I load your script inside of
<head>
<script type="text/javascript">
if (window.name=='logout')window.location.replace('logout.jsp');
window.name='logout';
</script>
</head> tags. But the script not worked...

this script working following way ,After login(login page), i click the back button in browser, then it allow back page(login page)...
But once i visit logout page, then i click back button, it can't allow back page...

Not perfectly worked..
I load your script inside of
<head>
<script type="text/javascript">
if (window.name=='logout')window.location.replace('logout.jsp');
window.name='logout';
</script>
</head> tags.

In which page did you put that script?
Did you also follow step 3 in my instructions?

After login(login page), i click the back button in browser, then it allow back page(login page)...

When you press BACK on any 'regular' page it should go to the login page but jump instantly to 'logout' before 'login' can display a second time.

But once i visit logout page, then i click back button, it can't allow back page...

Are you saying that once you have reached 'logout' you want to be able to use BACK to get to 'login'?

Or are you saying that once you get to 'logout' you want BACK to return to the last page you just visited?

Or are you saying that after you have reached 'logout' you want to be able to start at 'login' again without opening a new window/session?

hi,
I use onbeforeunload(). Its not worked .Because this script called when i click refresh button.
So i need only click back arraow, then called any script, and go to logout page.
Any otherway(jquery, JSF richfaces) to acheive this 'when i click back button then go to logout page'. Any one help me. I hope. Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.