Javascript 如何更改将根据document.referer加载的URL

Javascript 如何更改将根据document.referer加载的URL,javascript,Javascript,我需要用户被定向到一个特定的网址根据他来自的网站 <script> function abc(){ var ref = document.referrer; if (ref = /site1/) { window.location.href = "https://www.site1.wow"; } else if (ref = /site2/) { window.location.href = "https

我需要用户被定向到一个特定的网址根据他来自的网站

<script>
    function abc(){
    var ref = document.referrer;
    if (ref = /site1/) {
    window.location.href = "https://www.site1.wow";
    } else if (ref = /site2/) {
    window.location.href = "https://www.site2.wow";
    } else {
    window.location.href = "https://www.site.wow";
 }
}
</script>
}
}

您必须以不同的方式进行:

const parameters = new URLSearchParams(window.location.search);
这将从实际站点获取所有参数。 现在您必须测试它是否有您正在查找的参数,例如:

if(parameters.get("utm_source") && parameters.get("utm_source") === "abc"){
 console.log("It has this parameter")
}

你的问题是什么?如何使这个函数工作,它正确吗?这回答了你的问题吗?我需要知道站点是否有参数utm_medium或gclid。@LuizFelipeMachado参数?你所说的参数是什么意思?它在url中有这个吗?例如“”或类似“”的内容如果URL有utm_source=abc,它会将您指向第一个URL,如果有gclid=参数,它会将您指向另一个URL,如果没有参数,则指向第三个URL。@LuizFelipeMachado utm_source=abc?你的意思是类似于“”,所以url中有一个参数?没错
if(parameters.get("utm_source") && parameters.get("utm_source") === "abc"){
 console.log("It has this parameter")
}