Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a ‘back’ button… 4

Status
Not open for further replies.

codehopper

Technical User
Feb 13, 2004
5
GB
Hi there,
I was searching previous posts/FAQs for an answer to my problem, but couldn’t find it: is there a way I can have a reliable ‘back’ button, purely in HTML or similar, not involving JavaScript? This button needs to work on Internet Explorer without fail (most popular versions) and ideally on Netscape as well.

I have a vertically scrolling page with many thumbnail pics. When clicked, each thumbnail opens a new page (in parent window) containing bigger pic and item’s details. The back button is on this page. When clicked, it takes the user back to the same part of the previous page (for example, near the bottom) where the thumbnail was. In other words, the same functionality as the browser’s own back button. Here is the code I was using till I found that it doesn’t work with some versions/configurations of IE:
____________________________
<form>
<input type="button" value="Back" onClick="history.go(-1);return true;">
</form>
____________________________

I hope someone can help me out with this... any advice or code appreciated!
Thanks for your time,
Codehopper
 
well thats javascript

<a href="javascript:history.back()">back</a>

would a link do?

zzzzzz
 
Hi Deecee,
thanks for the quick response... is it possible for me to have a back button without invoking Javascript? The functionality of this button is vital, and it needs to work even on browsers with JS turned off. Please let me know if there are any other alternatives, maybe in DHTML or XHTML... or just plain ol HTML!
Thanks again for your help,
Codehopper
 

You cannot emulate the back button without using scripting of some kind.

If you wanted to avoid using client-side scripting (JavaScript / VBScript), then it is possible you could fake it using server-side scripting.

If you were to keep track of URLs, and hard-code a "Back" button with a specific URL when each page is delivered, it would have the desired result.

You should ask your hosting company if they support any server-side languages (ASP, PHP, JSP, etc), which would enable you to build a solution transparent to the user.

Hope this helps,
Dan
 
Building on Dan's reply, you could achieve this using a session cookie (in asp, php, jsp that I know of). Here is the pseudo-code I would use:

On loading the page, check to see if there is a session cookie (known to you) that contains the filename/identifier of the last page visited.

If the (known) session cookie exists then read the data from it and use it to build up the url for the "back" button (which you would then store in a variable for echoing out to the page later).

Put the filename/identifier of the current page into the (known) session variable.

If there is to be a "back" button on this page, echo the "back" button code to the page in the appropriate place.

Hope this helps you on your way,
Jeff
 

>> ...needs to work even on browsers with JS turned off. Please let me know if there are any other alternatives, maybe in DHTML...

DHTML requires a client-side scripting language, like JavaScript or VBScript... So having a DHTML solution with JS turned off wouldn't be much good to you. ;o)

Dan
 
ASP code, checks if referer page variable is empty, if so puts the javascript version on otherwise writes the referer page in as a link.

fairly simple to convert to PHP or Perl

Code:
	if request.servervariables("HTTP_REFERER") = "" then
	%>
      <a href="javascript:history.back(1)">Previous Page</a>
	 <%
	 else
	 %>
<a href="<% response.write request.servervariables("HTTP_REFERER") %>" title="Back a page">Previous Page</a>
	<%
	end if
	%>

but as everyone has said there is no way of doing this in HTml



Chris.

Indifference will be the downfall of mankind, but who cares?
 
True, there's no way of firing the Back button in HTML, but you can code your pages differently so you won't need to. Just use ordinary HTML bookmarks.

Code your thumbnail page like this:
Code:
...
<a name="t1" id="t1" href="picture1.htm">
<img src="thumb1.jpg" />
</a>

<a name="t2" id="t2" href="picture2.htm">
<img src="thumb2.jpg" />
</a>
...
(I include both name and id attributes for backward compatibility, modern browsers only need the id)

On you actual picture pages you do this:
Code:
...
<img src="picture1.jpg" /><br />
<a href="thumbnails.htm#t1">Back</a>
...
That should give you the desired functionality without using any scripting at all.

-- Chris Hunt
 
Hi,
thanks to everyone who contributed to this thread! I really appreciate your time (and patience, me being a newbie)... well, at least now I know that a back button is impossible without scripting of some sort. I'll try and use a few suggestions, incl. the server-side stuff, my hosts do support asp/php etc., so i'll look into that. If it still doesn't work out, it seems anchor tags are the next best solution, put on prev page and link the back button(s) to those. Anyway, many thanks again to all for the kind help!!
Codehopper
 
i really cannont understand why you need it done this way?

what is wrong with the back button? if i understood why you couldn't use the back button it could help me and others in teh future who might encounter this issue.

zzzzzz
 
deecee - it's in the third post

The functionality of this button is vital, and it needs to work even on browsers with JS turned off.

Another solution occurs to me. Assuming all your pictures will go back to the same thumbnail page, you could code the "back" links something like this:

Code:
<a href="thumbnails.htm" onclick="history.back();return false">Back</a>

Users with JS switched off will ignore the onclick event and go back to the top of the page they came from - which is not ideal, but better than nothing. The 90-odd percent of users with JS enabled will do a "Back button" instead. (I'm not a big JS developer, so you may need to tinker with the syntax a little to get it working)

-- Chris Hunt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top