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

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

问题描述

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

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));
}

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

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