Make anchor links refer to the current page when using <base>

后端 未结 12 1169
情书的邮戳
情书的邮戳 2020-11-30 03:29

When I use the html tag to define a base URL for all relative links on a page, anchor links also refer directly to the base URL. Is there a way to

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 04:09

    Here's an even shorter, jQuery based version I use in a production environment, and it works well for me.

    $().ready(function() {
      $("a[href^='\#']").each(function(){ 
        this.href=location.href.split("#")[0]+'#'+this.href.substr(this.href.indexOf('#')+1);
      });
    });
    

提交回复
热议问题