1

I need to change URL param (step=?) By JavaScript only.

My URL is,

http://domain.com/path/to/reach/5?step=1

I want to change the param 'step' by JavaScript only.

I need like this,

http://domain.com/path/to/reach/5?step=1
http://domain.com/path/to/reach/5?step=2
http://domain.com/path/to/reach/5?step=3   

I use some validations (show/hide) via step param only.

So I need refresh also, but this changes should stable.

I found lot of examples, those all are done by jQuery.

But I need it, only on JavaScript.

4
  • But i don't want jQuery based solution. Commented Jan 2, 2017 at 12:09
  • Have you used window.history.pushState? Commented Jan 2, 2017 at 12:13
  • @Praveen Kumar, Nope i'm not use that. What it does actually ? Commented Jan 2, 2017 at 13:00
  • Never mind. I gave a solution, which worked. But looks like you just chose an answer. :D Commented Jan 2, 2017 at 13:01

2 Answers 2

5

You can use the (rather-new) URL api:

var url = new URL(location.href)
url.searchParams.set('step', '...')

var modifiedUrl = url.toString();

If you're concerned about browser support, consider using a polyfill:

See MDN

Sign up to request clarification or add additional context in comments.

Comments

0

Use this code

location.search = " your query"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.