首页 > 解决方案 > 需要 window.location.href 行为解释

问题描述

我注意到,当您不将 window.location.href 绑定到某些事件浏览器时,我不会返回页面。请解释为什么会这样


   let link = document.getElementById('link');

   link.addEventListener('click',function(){
    window.location.href = "v.html"
   })

// the code above works just fine and i can go back in history afterwards
// I can't do the same with the code below

   if(1){
      window.location.href = "v.html"
   }

标签: javascript

解决方案


推荐阅读