Javascript 如何从外部页面的重定向URL中删除哈希? 当我在一个不同的页面中间进行一个锚调用时,浏览器的URL从锚中删除散列,但是返回到初始值。
最大的问题是,当我最终摆脱散列时,锚超链接停止工作 我尝试了不同的方法来解决这个问题,但目前没有一个有效Javascript 如何从外部页面的重定向URL中删除哈希? 当我在一个不同的页面中间进行一个锚调用时,浏览器的URL从锚中删除散列,但是返回到初始值。,javascript,jquery,Javascript,Jquery,最大的问题是,当我最终摆脱散列时,锚超链接停止工作 我尝试了不同的方法来解决这个问题,但目前没有一个有效 <a href="index.php#has1" onclick="changeURL()">Seccion1</a> function changeURL() { window.history.replaceState( {} , 'index.php#has1', 'index.php' ); alert("the url changes, but wh
<a href="index.php#has1" onclick="changeURL()">Seccion1</a>
function changeURL() {
window.history.replaceState( {} , 'index.php#has1', 'index.php' );
alert("the url changes, but when I close alert, url returns to its origin");
}
函数changeURL(){
replaceState({},'index.php#has1','index.php');
警报(“url更改,但当我关闭警报时,url将返回其原始位置”);
}
其他没有成功的选择:
//window.history.pushState(null, "", "index.php");
//window.location.hash='';
<script>
$('index.php#promo').click(function(){
event.preventDefault();
//the rest of the function is the same.
});
</script>
//window.history.pushState(null,“,”index.php”);
//window.location.hash='';
$('index.php#promo')。单击(函数(){
event.preventDefault();
//函数的其余部分是相同的。
});
预期结果:“www.mysite.com/index.php”
当前结果:“www.mysite.com/index.php.#has1”哈希首先有什么问题?锚停止工作。只需更改页面,而不是更改页面并转到锚点的高度。首先,哈希有什么问题?锚点停止工作。只需更改页面,而不是更改页面并转到锚定的高度。