Search code examples
javascriptjqueryhtmlhttp-redirectbrowser-history

Go back to previous page with modifed URL


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.


Solution

  • you can write like

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