Solved

history.go(-1)

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please explain purpose of GZIP 4 83
Level out logo and increase size? 16 52
Customising IE behaviour on certain pages 2 101
wordpress 4.7.4, theme 8 43
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

752 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