javascript - 在不引起重定向的情况下向 URL 添加片段?

标签 javascript jquery hash

有没有办法在不重定向的情况下将哈希 # 添加到我的 URL?

最佳答案

window.location.hash = 'something';

那只是普通的 JavaScript。

你的评论...

Hi, what I really need is to add only the hash... something like this: window.location.hash = '#'; but in this way nothing is added.

试试这个...

window.location = '#';

此外,不要忘记 window.location.replace() 方法。

关于javascript - 在不引起重定向的情况下向 URL 添加片段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4282069/

相关文章:

javascript - 在 URL 中使用井号获取 window.location.pathname - javascript

c++ - 为什么哈希函数返回一个 size_t,它是如何使用的?

JavaScript/jQuery : Divs not changing background color on loop

c++ - 在 main 之后立即导致堆栈溢出的代码

c++ - 如何实现经纬度值的邻近搜索?

javascript - Typescript 中带有函数的映射类型

javascript - 阻止滚动函数多次触发?

javascript - 哪个性能更好 : add and remove event listener on every render VS running an useEffect to update a ref

javascript - JQuery 滚动到 anchor - 仅定位某些链接

javascript - 如何以编程方式展开/折叠 Jarvis Widget?