Solved

history.go(-1)

Posted on 2002-03-21
4
1,112 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

27 Experts available now in Live!

Get 1:1 Help Now