最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to manipulate the URL with Javascript and JQuery? - Stack Overflow

programmeradmin1浏览0评论

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/page1

myapp/page2

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

Share Improve this question edited Jun 4, 2016 at 19:02 nbro 15.8k34 gold badges119 silver badges213 bronze badges asked Jul 6, 2011 at 19:06 Hugo MotaHugo Mota 11.6k9 gold badges44 silver badges61 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 8

pushState, as seen on github

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

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.

Set this value: window.location.href

  window.location.href = "myapp.com/page2";
发布评论

评论列表(0)

  1. 暂无评论