简体   繁体   English

Javascript:返回新参数

[英]Javascript : go back with new parameters

I have a problem with the history.back() function. 我有history.back()函数的问题。

I have three page A,B,C: 我有三页A,B,C:

  • the first one (A) has a link to the second (B) and the link contains parameters (?id=..). 第一个(A)有一个到第二个(B)的链接,链接包含参数(?id = ..)。
  • B has a link to C B有一个到C的链接
  • I go back from C to B with history.back() . 我用history.back()从C回到B.

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. 问题是back()函数实际上使用包含参数的A到B链接(来自历史),但我需要更改这些。

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). 所以我将history.back()更改为一个简单的href但当然,如果我点击后面,我会回到C页面(我不想要的)。

So is there a solution to use back() with different parameters? 那么有一个使用back()和不同参数的解决方案吗? (I use Angular, may be something can help). (我使用Angular,可能会有所帮助)。

A.html : 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 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 C.html

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

There's no way to alter your history with javascript. 没有办法用javascript改变你的历史。

Have you tried using the referrer property to figure out on Page "B", if you're coming from page "A" or "C"? 如果您来自“A”或“C”页面,您是否尝试使用referrer属性来确定页面“B”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM