How to detect if URL has changed after hash in JavaScript

后端 未结 17 1640
無奈伤痛
無奈伤痛 2020-11-22 17:02

How can I check if a URL has changed in JavaScript? For example, websites like GitHub, which use AJAX, will append page information after a # symbol to create a unique URL w

17条回答
  •  臣服心动
    2020-11-22 17:57

    In modern browsers (IE8+, FF3.6+, Chrome), you can just listen to the hashchange event on window.

    In some old browsers, you need a timer that continually checks location.hash. If you're using jQuery, there is a plugin that does exactly that.

提交回复
热议问题