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

manoj
  • 3,729
  • 5
  • 20
  • 41
  • 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. – mavrosxristoforos Oct 23 '13 at 05: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. – Ali Oct 23 '13 at 05: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` – manoj Oct 23 '13 at 05:27
  • 2
    check this thread...http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript – nik Oct 23 '13 at 05:28

1 Answers1

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.

Community
  • 1
  • 1
Sorter
  • 8,190
  • 5
  • 52
  • 63