Solved

history.go(-1)

Posted on 2002-03-21
4
1,173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

630 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