gpt4 book ai didi

javascript - 链接重定向协助

转载 作者:行者123 更新时间:2023-11-28 04:00:25 25 4
gpt4 key购买 nike

这是脚本:

<script>
if(document.location.href.indexOf('https://thedomain.com/collections/all?sort_by=best-selling') > -1) {
document.location.href = 'https://thedomain.com/pages/bestsellers';
}
</script>

问题是,当我输入 https://thedomain.com/////////////////////////////////////////collections/all?sort_by=best-selling 时,我该如何编写代码?

如何合并var correctURL= document.location.href.replace(/([^:]/)/+/g, "$1");每当我复制任何“/”“?”网页链接中的“_”“=”“-”字符。

底线是我不想被迫这样做(效率低下):

<script>
if(document.location.href.indexOf('https://thedomain.com/////////////////////////////////////////collections/all?sort_by=best-selling') > -1) {
document.location.href = 'https://thedomain.com/pages/bestsellers';
}
</script>

最佳答案

我不是 100% 确定您在问什么,或者为什么您的 url 中会有那么多斜杠,但您可以只匹配 url 的一部分以查看用户是否在正确的页面上。

if(document.location.href.indexOf('/collections/all?sort_by=best-selling') > -1) { 

document.location.href = 'https://thedomain.com/pages/bestsellers';
}

关于javascript - 链接重定向协助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43239888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com