【发布时间】:2020-09-04 07:36:54
【问题描述】:
这与此处的现有查询不同。
当 destination id 位于不同页面时,我正面临删除 #url。
这是我所做的: 有 2 个 HTML 页面:index.html 和 about.html。我在 index.html 页面中使用<div id="one"></div> 显示了各种菜单信息,而不是每个菜单项的单独页面,单击时删除#url 我已经分别尝试了以下几行。
history.pushState('', document.title, window.location.pathname);
var target = $(this.target);
但是,#url 不仅仅显示在 index.html 页面中。但是,当单击 about.html 页面中的菜单项时,#url 仍然可见(因为<div id=""></div> 在 index.html 中)。即使 destination id 在不同的页面中,你能帮我删除 #url。
【问题讨论】:
-
你能定义你获取哈希值的 URL 吗?
-
history.pushState()在我尝试时确实删除了哈希。this.target是什么? -
这似乎验证了您的要求。 (它围绕 event.preventDefault() 以避免点击有效但只触发脚本)stackoverflow.com/questions/28678548/…
-
嗨@HiteshKumar,当我在about.html中单击菜单项{目标内容在index.html中}时看到#url
标签: javascript html jquery css