Decay
Decay

Reputation: 53

history.back() and html links problems

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>

Upvotes: 0

Views: 177

Answers (1)

crazybob
crazybob

Reputation: 2317

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?

Upvotes: 2

Related Questions