当前位置: 代码迷 >> 综合 >> 使用window.location.href和document.referrer
  详细解决方案

使用window.location.href和document.referrer

热度:81   发布时间:2023-11-01 03:55:57.0

document.referrer来访页面的url

window.location.href 当前页面的url

在使用这两者并且想要在其后面加参数时应注意:判断window.location.href和window.location.href中是否包含?,包含拼接&,不包含拼接?。

if(document.referrer.indexOf('?')>-1){window.location.href = document.referrer+'&r='+Math.random();}else{ window.location.href = document.referrer+'?r='+Math.random();}



  相关解决方案