Can I prevent history.popstate from triggering on initial page-load?

前端 未结 5 1921
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 22:43

I\'m working on a site that serves content via AJAX.

If you click an item in the menu, a content div gets updated with $.get response, nothing fancy.

5条回答
  •  青春惊慌失措
    2020-11-30 23:20

    Using the native HTML5 History API you're going to run into some problems, every HTML5 browser handles the API a little bit differently so you can't just code it once and expect it to work without implementing workarounds. History.js provides a cross-browser API for the HTML5 History API and a optional hashchange fallback for HTML4 browsers if you want to go down that route.

    For upgrading your website into a RIA/Ajax-Application you can use this code snippet: https://github.com/browserstate/ajaxify

    Which is part of the longer article Intelligent State Handling which goes into explanations about hashbang, hashes and the html5 history api.

    Let me know if you need any further help :) Cheers.

提交回复
热议问题