-1

I get a variable from session storage like this:

var my_variable = sessionStorage.getItem("some_value");

Using Jquery or plain JS how can I paste the value of my_variable into the current document URL, inside a query string?

Example: If my_variable has the value "Hello_world", then the document URL should look like this:

www.example.com/some_page/index.html?q="Hello_world"

Malasorte
  • 1,153
  • 7
  • 21
  • 45

1 Answers1

1

Without redirection it's possible with History API:

JS

history.replaceState(history.state, '{your-new-url}', '{your-title(optional)}');

Also check, if the browser support is enough corresponding to your requirements.

Read more here.

jedrzejginter
  • 402
  • 3
  • 10