2

Using Javascript, I'm attempting to setup a redirect that will go back to the previous page with a newly appended value added to the url.

For example, if I landed here:

http://google.com/

Then navigated to:

http://google.com/redirect

I would expect to ultimately end up at:

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

Javascript to head back 1 page:

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

This works, but I'm not sure how I'd go about appending the query string.

Rich
  • 1,136
  • 3
  • 16
  • 36

3 Answers3

2

You're probably looking to go to the referrer having modified it a bit.

Then do:

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

(if I've got what you were looking for)

nicael
  • 18,550
  • 13
  • 57
  • 90
1

you can write like

<script>
   var a =  window.history.go(-1)+'your query string';
location.href = a;
</script>
vandy
  • 305
  • 2
  • 12
0

You may want to look up the replaceState() method of the History API.

There is a simple example of its use at: http://blog.scoutapp.com/articles/2010/12/07/manipulating-browser-history-with-javascript-pushstate-replacestate

It is also discussed on StackOverflow here: history.replaceState() example?

Community
  • 1
  • 1