如何从网址中删除定位标记? [英] How do you remove anchor tags from URL?

查看:50
本文介绍了如何从网址中删除定位标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除在切换手风琴或包含指向页面另一部分的锚点的链接时使用的锚点标签.

I am trying to remove the anchor tags used when toggling the accordions or a link that includes an anchor to another part of the page.

http://rivo.wpengine.com/why-rivo/#toggle-id-3

我想删除此URL的#toggle-id-3 部分.

I would like to removing the #toggle-id-3 part of this URL.

我可以对 .htaccess 文件做些什么,也许使用mod_rewrite?

Can I do something with the .htaccess file, maybe using mod_rewrite?

推荐答案

您不能使用htaccess或mod_rewrite删除URL片段,因为它们从未被发送到服务器.就服务器而言,它们不存在.您需要使用javascript或其他客户端解决方案将其删除.

You can't use htaccess or mod_rewrite to remove URL fragments because they are never sent to the server. As far as the server is concerned, they don't exist. You'll need to use javascript or some other client side solution to remove them.

例如,来自:删除片段在没有JavaScript的URL中导致页面重新加载

// remove fragment as much as it can go without adding an entry in browser history:
window.location.replace("#");

// slice off the remaining '#' in HTML5:    
if (typeof window.history.replaceState == 'function') {
  history.replaceState({}, '', window.location.href.slice(0, -1));
}

这篇关于如何从网址中删除定位标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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