history.pushState 實現ajax無重新整理更改url

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   ar   sp   div   on   

暫時沒啥心得,直接上例子。

 1 <html> 2 <head> 3 <title> 4 fasd 5 </title> 6 <script> 7 window.addEventListener(‘popstate‘, function(e){ 8   if (history.state){ 9     var state = e.state;10     console.log(state.title);11   }12 }, false);13 14 function ok(id){15     var url = ‘http://www.test.com/test.php?arg=‘ + id;16     var title = id + ‘title‘;17     var state = {18             title: title,19             url: url,    20         };21     history.pushState(state, title, url);22     console.log(url);23 }24 </script>25 </head>26 27 <body>28 1</br>29 <a onclick="ok(1);">1****1</a></br>30 <a onclick="ok(2);">2****2</a></br>31 <a onclick="ok(3);">3****3</a></br>32 <a onclick="ok(4);">4****4</a></br>33 <a onclick="ok(5);">5****5</a></br>34 <a onclick="ok(6);">6****6</a></br>35 </body>

 

參考:

http://yansong.me/2013/01/11/learning-history.pushState-and-history.replaceState.html

http://www.welefen.com/use-ajax-and-pushstate.html

 

history.pushState 實現ajax無重新整理更改url

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.