2

Here i have a URL in Browser Address bar i want to replace path of Address bar using jQuery. Some try from my side is as below Consider url as below

http://localhost/catID/10/itemID/20

when i run

history.pushState("CatID", "Title", "21")

it change location bar as

http://localhost/catID/10/itemID/21

but i want result as

http://localhost/catID/21

how can i do this using jQuery

4
  • Are you trying to redirect to another page, or you are just trying to obfuscate the URL? Because if you are trying the second, it won't work. Commented Oct 23, 2013 at 5:22
  • You can use split function for splitting the string then get what index you need and redirect it through window.location hope you get what you need. Commented Oct 23, 2013 at 5:24
  • i want only to change url of location bar from http://localhost/catID/10/itemID/20 to http://localhost/catID/21 not to page load of link http://localhost/catID/21 Commented Oct 23, 2013 at 5:27
  • 2
    check this thread...stackoverflow.com/questions/136458/… Commented Oct 23, 2013 at 5:28

1 Answer 1

1

Query not needed. Plain js will do. Just add this code in your function and replace the string with the required arguments. Try it in the console, for an immediate effect ;D

window.location = "http://localhost/catID/10"

If you do not want to reload the page or use # for changing the url, then use window.onpopstate Modify the URL without reloading the page

Read this article on mozilla site.

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

1 Comment

this reload page i want only to change only location bar text without reloading page

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.