Malasorte Malasorte - 1 year ago 71
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"

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download