Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Javascript - History browse back to prev page

 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My jsp page comes up on clicking "OK" on the previous page. Lets say the previous page name to be "prevScr" and present one to be "crntScr"

Now on the present jsp page, I perform some actions which would re-load the page again and again. The problem is there is a "Cancel" button on the current screen.

Here is code:

<td><html:button value="Cancel"
property="cancel" on click="javascript:history.go(-1);"></html:button>
</td>

When you click on it, it goes to the previous history and it shows the same "crntScr" (because I would have perfomed some actions that re-loaded the page) but what I really want is it should go to "prevScr" page.

Is there a method that identifies the previous page? Thank you for all your time and responses.

Luke.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to skip back 2 pages? If you cahnge -1 to -2, would that do it for you?

Eric
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Eric, but I do not have a account of how many pages we have to go back like 1 or 2. But everytime the page re-loads there should be some counter increment. Is there a way a dyanmic counter can be made so that we can go x number of pages back.

Thanks,
Luke.
 
Luke Zechariah
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Got the solution:
In the jsp:
<BODY on_load="incCounter">

<html:hidden name="ReceiptForm" property="counter"/>

function incCounter()
{
var cntr = document.forms[0].counter.value;
cntr--;
document.forms[0].counter.value = cntr;
}
<td><html:button value="Cancel" property="cancel"
on_click="windowHandle();"></html:button>
</td>
function windowHandle()
{
var x = document.forms[0].counter.value;
javascript:history.go(x);
}


In the ReceiptForm:
private int counter = 0;

Thanks Eric for all the help.
Luke.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic