Malasorte Malasorte - 8 months ago 39
Javascript Question

Paste variable value into URL query string

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
into the current document URL, inside a query string?

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


Without redirection it's possible with History API:


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.