首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果url是某个路径,则添加参数

如果url是某个路径,则添加参数
EN

Stack Overflow用户
提问于 2020-10-26 19:48:11
回答 1查看 39关注 0票数 0

我有一个脚本运行的地方,如果有一个特定的URL,然后这将添加一个参数。例如,如果这个URL子文件夹中有/de,则添加?_sft_language=german。如果为/sp,则添加?_sft_language=spanish。我用JavaScript编写了下面的代码,但它运行了多次,但我只想让它运行一次。

代码语言: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;} 


}); 

有谁有什么想法吗?

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-10-26 20:01:41

您可以检查您是否已经添加了此参数:

代码语言:javascript
复制
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;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64536534

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档