How can I change the page URL without refreshing the page?

前端 未结 4 513
日久生厌
日久生厌 2020-11-30 23:46

How do I change the URL without refreshing the page?

I\'ve built a website with CodeIginer and I want to implement AJAX and JQuery in one of my pages. The problem is

4条回答
  •  不知归路
    2020-12-01 00:22

    Use hash tags via Javascript, so in the button's click event handler: location.hash = "param2" Which will change http://example.com/mypage/#whatever to http://example.com/mypage/#param2

    Of course, you could also put your "folders" after the hash, so, with a base url of http://example.com/ you then add: location.hash = "/MyPage/MySubPage/MyInfo"; which changes it to http://example.com/#/MyPage/MySubPage/MyInfo

提交回复
热议问题