jQuery,将URL捕获为变量

时间:2018-07-26 10:02:33

标签: jquery cookies

使用jQuery,我正在尝试捕获当前页面的当前URL并将其存储为变量,还修剪并添加了新地址的一部分。

代码中的解释。

if (!!$.cookie('ppc_campaign') || $.cookie('organic')) {
    if(window.location.contains("/lpt/") || ("/lp/")) {
        $ppc_url = 'capture url here but remove everything before the ? character and concatenate https://newurl.com at the start';
        $.cookie('ppc_campaign', $ppc_url, { expires: 28, path: '/' });
    }
    else {
        $.cookie('organic', 'https://anotheraddress.com/split?campaign=organic', { expires: 28, path: '/' });
    }

}

1 个答案:

答案 0 :(得分:0)

以纯jQuery样式:

var currentUrl = $(location).attr('href');

位置对象还具有其他属性,例如主机,哈希,协议和路径名。