Search code examples
javascriptangularjsback

Javascript : go back with new parameters


I have a problem with the history.back() function.

I have three page A,B,C:

  • the first one (A) has a link to the second (B) and the link contains parameters (?id=..).
  • B has a link to C
  • I go back from C to B with history.back().

The problem is that back() function use in fact the A to B link (from the history) that contains the parameters but I need to change these.

So I changed history.back() to a simple href but of course, now if I click on back, I go back to C page (what I don't want).

So is there a solution to use back() with different parameters? (I use Angular, may be something can help).

A.html :

<body ng-controller="AuthentCtrl">
    <div align="center">
        <button ng-click="location.href = 'view/listing.html?id=' + id + '&first=' + newAuthent;">Go!</button>
        <br/>
    </div>
</body>

B.html

<body onload="init()">
<script>
    function init(){
        var params = location.search.substring(1).split('&');
        id = params[0].split('=')[1];
        var firstCo = params[1].split('=')[1];
        // execute some code, function of parameters
    }
</script>
</body>

C.html

<body>
    <div align="center">
        <button ng-click="history.back()">Go!</button>
        <br/>
    </div>
</body>

Solution

  • There's no way to alter your history with javascript.

    Have you tried using the referrer property to figure out on Page "B", if you're coming from page "A" or "C"?