使用 jquery 隐藏 url 标签

发布于 2024-09-26 12:34:11 字数 337 浏览 1 评论 0原文

我需要代码来隐藏 jQuery 中 url 中的主题标签;我正在开发 OnePageSite,我希望在单击链接时获得“www.mysite.it”而不是“www.mysite.it/index.php#hashtag”。 这是Mootools 1.x的一段代码;有没有办法用 jQuery 来做同样的事情? 先感谢您。 此致。

if(window.location.href.indexOf('#')>-1) {
  window.location.replace(window.location.href.substr(0,window.location.href.indexOf('#')));
}

I need the code to hide the hashtag in the url in jQuery; I'm working on a OnePageSite and I wish to obtain "www.mysite.it" and not "www.mysite.it/index.php#hashtag" when clicking on a link.
This is a piece of code for Mootools 1.x; is there a way to make the same with jQuery?
Thank you in advance.
Best regards.

if(window.location.href.indexOf('#')>-1) {
  window.location.replace(window.location.href.substr(0,window.location.href.indexOf('#')));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2024-10-03 12:34:11

该代码是 JavaScript,完全不依赖于任何 MooTools 函数,您可以在使用(或不使用)任何框架的情况下使用它。

That code is JavaScript and not at all dependent on any MooTools functions, you can use it with (or without) any framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文