Can Re-writeModify URL with javascriptJquery after page load - Stack Overflow

Is it possible to re-write URL without reloading the page via jQueryJavascript?Let's say you have

Is it possible to re-write URL without reloading the page via jQuery/Javascript?

Let's say you have the following URL:

can we append the value: /pId=XYZ

So you can get

Is this possible?

Is it possible to re-write URL without reloading the page via jQuery/Javascript?

Let's say you have the following URL:

http://stackoverflow./questions/ask

can we append the value: /pId=XYZ

So you can get

http://stackoverflow./questions/ask/pId=XYZ

Is this possible?

Share Improve this question edited Jun 14, 2017 at 8:49 Malcolm Salvador 1,5663 gold badges22 silver badges41 bronze badges asked Aug 17, 2012 at 13:08 BJ PatelBJ Patel 6,27811 gold badges50 silver badges84 bronze badges 1
  • It's very easy to do a proper formatting of your question, maybe you could do it? – Olivier Pons Commented Aug 17, 2012 at 13:59
Add a ment  | 

5 Answers 5

Reset to default 6

All you can change without redirecting is the hash part of url:

document.location.hash = "whatever";

Yes you can, and you don't need jquery : simply use the History API : https://developer.mozilla/en-US/docs/DOM/Manipulating_the_browser_history

Beware that it's usually a little painful to handle history in a plex ajax application, as you have to handle state serialization of the pages, state loading, and so on. And you can't apply this to a badly designed site as are many ajaxified sites. And this won't work on "old" browsers like IE9.

Yes we can, but only on browsers implementing pushState.

See other answers here

you can get the current Url with

var url = document.location.href;

then you add the part to the url

url += "/mySubFolder";

rest of my post didnt fit the question ... i should read more carefully :( !

After encountering this problem, I think the @DenysSéguret answer is exactly what you need.

When it's supported by the browser, you can use

window.history.pushState(stateObj, title, url);

Or

window.history.replaceState(stateObj, title, url);

As stated by @DenysSéguret, you can find the documentation at
https://developer.mozilla/en-US/docs/Web/API/History_API

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1740185319a4204418.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信