Solved

history.go(-1)

Posted on 2002-03-21
4
1,076 Views
Last Modified: 2006-11-17
In my page, there is a BACK button, when user click it, I call javascript:history.go(-1). The problem
is when there is nothing to go back, I want to hide this BACK button(or disable it).
Thanks!
0
Comment
Question by:apig
  • 3
4 Comments
 

Accepted Solution

by:
trekkee earned 40 total points
ID: 6887189
the button object in HTML has a "Visible" property, and a "Disabled" property you can use.  

Just test if history.go(-1) = '' or the length(history.go(-1)) = 0 and if so set myButton.Visible = false.

This should work for you.
0
 

Author Comment

by:apig
ID: 6889544
yes I agree with you but the question is how to write the code.

It is not a button, it is a image.

Here is my code related to this issue, it always get an "syntax error". Thanks for any further advice.

<script language=Javascript>
<!--
function MM_showHideLayers() {
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

//-->
</script>



<div id=layer1  style="VISIBILITY: hidden"><a href="#">
<img src="/Hr/ourpeople/whoswho/images/Back_2.gif" width="70" height="26" border="0" onclick="JavaScript:history.go(-1)"></a>
</div>

<script language=JavaScript>
if (history.go(-1)) ! = "")
{ MM_showHideLayers('layer1','','show');}
</script>    
0
 

Author Comment

by:apig
ID: 6889595
Now I modified the last part of the code as following, there is no more syntax error any more. But the BACK button now will be there as long as the length of this history is not 0. What I want is to hide it whenever there is nothing to go back.

<script language=JavaScript>
if (history.length != 0) { MM_showHideLayers('layer1','','show');}
</script>    
0
 

Author Comment

by:apig
ID: 6889726
Hi I found out a way to work around it. In fact I don't think I explained my question very well.

Anyway thanks.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now