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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if at - history start -

Status
Not open for further replies.

MDA

Technical User
Jan 16, 2001
243
US
Hi all,

I have a simple hyperlink text that brings the user back one page on an asp page:

<a class=tbl-nav href=&quot;JavaScript:history.back(1)&quot;><- Go Back</a>

How can I hide this link if the user is already at the first page. Is there syntax to check where the user is in respect to history, i.e. page 1, 2, 3?

Any ideas are greatly appreciated.

MDA
 
Here is a start for you. You can play with hiding and showing <div>'s or something to show and hide the link. Probably easier if you are using asp, php, cf, etc.
Code:
<script language=&quot;javascript&quot;>

var myHistory = history.length;

function showHistory() {

if(myHistory > 1) {
	
document.location.href = history.back(1);

}

if(myHistory < 1) {
		
alert(&quot;There is no History&quot;)
			
}			
}	

</script>

<input type=&quot;button&quot; name=&quot;mine&quot; value=&quot;Show History&quot; onClick=&quot;showHistory()&quot;>
DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
You can hide the anchor tag itself instead of using divs.
Code:
<html>
<head>
	<title>Untitled</title>
<script>
function checkHistory(){
  if (history.length<1){
    document.getElementById(&quot;backLink&quot;).style.display=&quot;none&quot;;
  }
}  
</script>	
</head>

<body onLoad=&quot;checkHistory()&quot;>

<a id=&quot;backLink&quot; href=&quot;javascript:history.go(-1)&quot;>Back</a>

</body>
</html>
Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
Hey thannks for the help guys....

I went with Helltel's solution. Works great exceot when I get back to the first page the back link does not hide again.

Does the statement: <body onLoad=&quot;checkHistory()&quot;> fire only the first time when the page is opened or every time you go to a new page?

Thanks again for your help..

MDA
 
Hmmm, not sure of the answer.
It's not that the checkHistory isn't firing again. What it is, the fact you've been forward and then come back gives you a &quot;history&quot;. History doesn't just mean backwards, it can be forwards too, so although history.go(-1) doesn't take you anywhere history.go(1) would take you forwards again, so it's still a history. See what I mean?

I'll keep thinking.
Unless anybody else has an answer? Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
Thanks for the help.. I came up with a solution but I am not really familar with scripting languages so not sure how to complete this idea...

The idea is that I start the page with a string = 1, then when I move to the next page I pass the string + 1. However, I dont know how to check the string in the script example you gave me. And also not sure if I can pass a variable in the back statement to - 1.

EX:

Session = CStr(Request.querystring(&quot;SessionNum&quot;))
IF Session = &quot;&quot; THEN Session = 1 ELSE Session = Session + 1 END IF

--- Need help with the parts below... I thought If I just say when session = 1, Hide but that does not cut it.

<script>
function checkHistory(){
if (session = 1{
document.getElementById(&quot;backLink&quot;).style.display=&quot;none&quot;;
}
}
</script>

AND also need to pass the variable - 1 ?

<a class=m-tbl-nav id=&quot;backLink&quot; href=&quot;JavaScript:history.back(1)&quot;><- Go Back</a>

Any ideas???

Thanks a million..

MDA
 
I'm sorry I've had virtually no time for anything today.
The if statement is slightly wrong. You normally use VBScript right?[bigsmile]
Code:
if (session==1){
etc.
Maybe you could make the link call a function which takes 1 from a hidden form input value which can then be passed as a variable in the querystring, if you submit the form at the end of the function with the action as another page. But then you're not using the history anyway.
That probably doesn't quite make sense, but I have a bad headache and need to go home!
Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top