Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

history.go(-1)

Posted on 2002-03-21
4
Medium Priority
?
1,197 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 160 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to dynamically set the form action using jQuery.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

715 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