1
votes

I created back button where page1 and page2 redirects to page3. When back button is clicked on page3, it redirects back to page1 or page2 accordingly. I used document.referrer which sometimes returns page itself instead of parent location. That is when click back button on page3 it redirects to page3.

Tested with different browsers as Firefox, Chrome: same result

function GoBackWithRefresh(event) 
{
    if ('referrer' in document) 
    {
        var ref = document.referrer;
        console.log("document referrer_____<BR>"+ref);
        window.location = document.referrer;
        /* OR */
        //location.replace(document.referrer);
    } 
    else 
    { 
        console.log("window history____"+window.history);
        window.history.back(); 
    }
}

That is when click back button on page3 it redirects to page3 where it is suppose to go back to parent page.

1

1 Answers

2
votes

You can either use window.history.go

For example :

function GoBackWithRefresh() 
{
    window.history.go(-1);
}