Could a page display diferrent content if the URL hash changes?

前端 未结 7 1920
名媛妹妹
名媛妹妹 2021-01-14 15:24

How could a page display different content based on the URL hash?

I\'m not talking about the browser scrolling down to display the anchored section, but something li

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 15:48

    It is fairly common among AJAX-heavy applications (think Gmail) to be able to have all the AJAXy stuff while still making it possible for you to bookmark a particular page or link someone to a particular page. If they didn't do this, it would be considered bad for usability. It is fairly easy to get the URL hash by doing window.location.hash - so you can then have a switch-like statement on page load to execute a particular set of Javascript functions if a hash is present.

    Some jQuery plugins that achieve this functionality: history/remote, history.

提交回复
热议问题