Assigning to [removed].href without clobbering history

前端 未结 6 1238
渐次进展
渐次进展 2020-12-01 19:04

In testing document.location.href, I have observed that when the user initiates an action that results in javascript that assigns to document.location.href, the new URL is a

6条回答
  •  孤街浪徒
    2020-12-01 19:51

    I was facing the same problem and found this workaround which worked for me

    instead of

    function onAjaxCallback(evt){
        location.href=newLocation;
    }
    

    i wrapped the location.href call around a setTimeout. Seems to do the trick. My history's behaving fine now. Hope that helps

    function onAjaxCallback(evt){
        setTimeout(function(){
            location.href=newLocation;
        },0)
    }
    

提交回复
热议问题