Detect change in hash value of URL using JavaScript

前端 未结 3 1215
清酒与你
清酒与你 2021-01-30 14:05

I\'m working on a simple application which is single page based (due to project restrictions) and has dynamic content. I understand the dynamic content alright but what I don\'t

3条回答
  •  天涯浪人
    2021-01-30 14:13

    You can listen to the hashchange event:

    $(window).on('hashchange',function(){ 
        $('h1').text(location.hash.slice(1));
    });
    

提交回复
热议问题