Retrieve specific hash tag's value from url

前端 未结 4 1870
误落风尘
误落风尘 2020-12-13 16:59

In raw Javascript, how would one go about checking that a specific hash tag exists in a url, then grab the value?

Example: http://www.example.com/index.html#hashtag1

4条回答
  •  心在旅途
    2020-12-13 17:24

    jQuery BBQ (back button and query) leverages the HTML5 hashchange event to allow simple, yet powerful bookmarkable #hash history. In addition, jQuery BBQ provides a full .deparam() method, along with both hash state management, and fragment / query string parse and merge utility methods.

    In short: This library allows you to dynamically change a hash "query string" within your page and have the URL match. It also allows you to dynamically pull values and normalizes working with the "query string." Finally it will add the query strings into the history which allows the back button to function as a navigation between previous query hash values.

    A good move for UX would be to check out a library like jQuery BBQ :)

提交回复
热议问题