0

I have a link list who call other blocks ids in the page. So when I used my goBack() function, instead of reloading the last page, it gives me the same page with the latest clicked inks.

I thought I had a solution. I incremented a variable each time the user click on a link in the list, for then use the incremented var as a parametre of history.go() but it doesn't work.

<script>
var count;
function backward()
{
    count = -1;
    count--;
    return alert(count);
};

if(typeof count != "undefined")
{
    function goBack()
    {
        history.go(count);
    }
}

else
{
    function goBack()
    {
        history.back();
    }
}
</script>
JLRishe
  • 99,490
  • 19
  • 131
  • 169
Decay
  • 53
  • 8

1 Answers1

2

A better solution than counting clicks would be to pass the url of the previous page as a POST/GET parameter. Then instead of using history.back() you should redirect to the previous page:

var url = ... // get the previous page url from the GET parameters
window.location = url;

In order to retrieve the GET parameter see: How to retrieve GET parameters from javascript?

Community
  • 1
  • 1
crazybob
  • 2,307
  • 1
  • 21
  • 26
  • However, why the first script I tried does not work? Is there any syntax error, or is it about logic? – Decay Aug 29 '13 at 11:37