返回修改后的上一页 URL

Go back to previous page with modifed URL

使用 Javascript,我正在尝试设置一个重定向,该重定向将返回到上一页,并将新附加的值添加到 url。

例如,如果我降落在这里:

http://google.com/

然后导航到:

http://google.com/redirect

我预计最终会在:

http://google.com/?redirect=successful

Javascript 返回 1 页:

<script>
    window.history.go(-1);
</script>

这有效,但我不确定我将如何附加查询字符串。

您可能希望访问稍微修改过的引荐来源网址。

然后做:

location.href = document.referrer + "?redirect=successful"

(如果我有你要找的东西)

你可以这样写

<script>
   var a =  window.history.go(-1)+'your query string';
location.href = a;
</script>

您可能需要查找历史记录的 replaceState() 方法 API。

有一个简单的使用示例:http://blog.scoutapp.com/articles/2010/12/07/manipulating-browser-history-with-javascript-pushstate-replacestate

在 Whosebug 上也有讨论:history.replaceState() example?