[thelist] dynamic back button (javascript)

Brian Cummiskey Brian at hondaswap.com
Wed Feb 9 16:31:53 CST 2005

Hi folks-  me again with another JS question.

I'm working on a huge campaign for an internal intranet application (all 
win2k/ie6 workstations).  This is coded in classic vb/asp on the back 
and js for the client side.

the web-based application is launched in a 3rd party scripter 
(basically, and IE-like environment, but no menus, back button, etc -- 
similar to full screen mode (F11).  the Backspace, Escape, and enter 
keys are also disabled, as are right mouse clicks for navigation 
purposes [backspace and enter will still work when active on a form 

I'm trying to set it up so that the "back button" - a button I 
physically put into the script - is dynamic.

1st logical answer was to use the history(-1) function.  This is exaclty 
what i want- BUT the problem lies in that IF the agent entered anything 
into the form on the page, and then goes back, the data entered is lost. 
  I need to set a cookie for it so that it will be filled in when the 
agent returns to the page once again (and doesn't look stupid asking the 
customer for the same information twice because the system lost it).  My 
pages are all set up to handel both forward and backwards movement for 
setting the cookies.

My next idea was to place a hidden var on every page, using the 
HTTP_REFERRER as the value for the back button's action.  (see code 
below-  i used the same setup) This works great too--  until you want to 
go back more than 1 page.  This just puts you in an endless 
back-and-forth loop between the current page and the one just before it 
back to the orig page, and so on.

So, I came up with the idea to combine the two: (with all the other code 
stripped out):

<script type="text/javascript">
function goBack() {
	var theform = document.getElementById("frmdefault");
	var previouspage = history(-1);

	theform.action = previouspage;
<form name="frmdefault" id="frmdefault">
	<input type="button" value="Back" onclick="goBack();" />	
	// other form stuff here....

Well, this fails miserably.  :D  I expected it to not work.  But, I 
can't seem to think of the way to DO that, but have it work.
firefox's JS tool (which is what i use to test/develop with) says 
"history is not a function" is the error.


It's IMPOSSIBLE - not just time consuimg - to physically hard code in 
every script's previous page (probably 50+ pages by now and growing)). 
Some pages have more than 1 lead into them, so it would be a guess at 
best to send them back to one or the other.  In fact, that puts me right 
back on the HTTP_REFERER solution i tried above.

Sessions are NOT an option.  This setup is used on most of our app's 
without a hitch.  However, this is the first time i've ever had 
multiple->single page paths.

lol  its a big circle.  anyone have a "square" way out of it?  :P



More information about the thelist mailing list