我有一个脚本运行的地方,如果有一个特定的URL,然后这将添加一个参数。例如,如果这个URL子文件夹中有/de,则添加?_sft_language=german。如果为/sp,则添加?_sft_language=spanish。我用JavaScript编写了下面的代码,但它运行了多次,但我只想让它运行一次。
$(document).ready(function() {
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/de/partner/')){var url = document.location.href+"?_sft_language=german";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/da/partner/')){var url = document.location.href+"?_sft_language=danish";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/nl/partner/')){var url = document.location.href+"?_sft_language=dutch";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/fr/partner/')){var url = document.location.href+"?_sft_language=french";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/it/partner/')){var url = document.location.href+"?_sft_language=italian";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/ja/partner/')){var url = document.location.href+"?_sft_language=japanese";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/ko/partner/')){var url = document.location.href+"?_sft_language=korean";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/no/partner/')){var url = document.location.href+"?_sft_language=norwegian";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/es/partner/')){var url = document.location.href+"?_sft_language=spanish";document.location = url;}
if(!window.location.href.match('_sft_language') && window.location.href.match('testsite.com/partner/')){var url = document.location.href+"?_sft_language=english";document.location = url;}
}); 有谁有什么想法吗?
谢谢!
发布于 2020-10-26 20:01:41
您可以检查您是否已经添加了此参数:
if(!window.location.href.match('_sft_language') && window.location.href.match('testingsite.com/de/partner')){
var url = document.location.href+"?_sft_language=german";
document.location = url;
}https://stackoverflow.com/questions/64536534
复制相似问题