我设法创建一个条件来检测 anchor 链接,但之后如何将 anchor 链接存储在我的anchor_num变量中,以便我可以将使用重定向到特定的网址?
<script type="text/javascript">
$(function(){
if(window.location.hash){
var anchor_num = "anchorString";
window.location = "#"+ anchor_num;
} else
{
//redirect to default page
}
});
</script>
最佳答案
通过附加或更改哈希值,浏览器不会刷新您的页面。设置哈希值后,您应该调用 window.location.reload():
window.location = "#"+ anchor_num;
window.location.reload()
关于javascript - 如何存储用户输入网址( anchor 链接)并使用 window.location 重定向用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16667782/