我设法创建一个条件来检测锚链接,但是在那之后如何将锚链接存储在我的anchor_num变量中,以便可以将使用重定向到特定的url?

<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()

07-25 21:47
查看更多