开发者

Append bannercode from a webpage

I've got a problem I'm having trying to append a bannercode to the end of an URL. The customer journey is as follows:

  • Person receives an email which contains a link to a site (SITE1), the URL will contain a banner code e.g. www.site1.com?banner=helloworld
  • Once the person is on this site, there are 2 buttons which take the customer to a second site:
    • Button 1 goes to https://www.site2.com/page1
    • Button 2 goes to same URL/page2

 

$(document).ready( function () {
    var banner = String($.query.get('banner'));
    if(banner){
        href = $('a[href^="https://"]').attr("href") + "?banner=" + banner;    
        $('a[href^="https://"]').attr("href", href);
    }
});

Basically what happens is, the piece of code I have makes both buttons go to the same URL for example button 1. How can I get the script to not change the URL for开发者_如何学Go all buttons? Thanks in advance.


Do I understand you right: you want to add banner part for every link, but keep the original part unchanged?

$(document).ready(function(){
var banner=String($.query.get('banner'));
if(banner){
    $('a[href^="https://"]').attr('href',function(){
        return this+'?banner='+banner;
    });
}
});

or in shorter:

$(document).ready(function(){
    (banner=$.query.get('banner'))?$('[href^=https]').attr('href',function(){
            return this+'?banner='+banner}):null;
})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜