从网址中移除哈希标签(#) [英] Remove hashtag(#) from url

查看:103
本文介绍了从网址中移除哈希标签(#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望散列标签在使用后从URL中移除。
例如,当我点击下面的链接时:

I want hash-tags to be removed from URL after they are used. For example, when i click on the link below:

<a href="#btnq1"><button type="button" name="" value="" id="btnq1">Just a button</button></a>

我希望在页面的URL中出现的哈希标签#btnq1在被删除后此链接上的操作发生。
我尝试了下面的jquery代码没有成功:

I want the hash-tag #btnq1 that appears to the URL of the page to be removed just after the action on this link happens. I tried the below jquery code with no success:

$('#btnq1').click(function(event){
   event.preventDefault();
   // your action
});

即使这样做,那么我如何实现它来为每个添加的哈希标记到URL?
我想用javascript来解决它。

And even if this works, then how do i implement it to work for every hash tag that is added to the URL? I would like to solve it using javascript.

推荐答案

您可以尝试一下:

You could try that:

$(window).on('hashchange', function(e){
    history.replaceState ("", document.title, e.originalEvent.oldURL);
});

这篇关于从网址中移除哈希标签(#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆