How to manipulate the URL with Javascript and JQuery?

只愿长相守 提交于 2020-01-21 07:20:19

问题


I want to make a page with a lot of Javascript interactions. However, while a user navigates through the page the URL must change too. So, when the user shares the URL or saves it, it can lead him to the actual state he was.

How can I do that?

Examples:

myapp.com/page1

myapp.com/page2


回答1:


pushState, as seen on github




回答2:


Answered by this SO question: Change the URL in the browser without loading the new page using JavaScript




回答3:


The only part of the url (or location) that you can change without reloading the page, is the hash. That is the part behind the #. Many ajax enhanced applications make use of this, including Twitter. You can change this hash on the go, and interpret the hash tag on page load to initialize the page to the correct state.




回答4:


Set this value: window.location.href

  window.location.href = "myapp.com/page2";


来源:https://stackoverflow.com/questions/6601609/how-to-manipulate-the-url-with-javascript-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!