javascriptjqueryhtmlaffiliateaweber

Grabbing link value using JavaScript and appending it to image tag


I'm looking to create a proper postback for an affiliate system. It's quite similar a request to:

Grab a section from a URL and append it a link using jQuery

But it's a little beyond me to capture it the same way. The basic link I need to call in a hidden image tag or JavaScript on a thank you page is:

<img border="0" src="http://example.com/idevaffiliate/sale.php?profile=12345&idev_saleamt=123&idev_ordernum=VALUE" width="1" height="1">

or

<script language="JavaScript" type="text/javascript" src="http://example.com/idevaffiliate/sale.php?profile=12345&idev_saleamt=123&idev_ordernum=VALUE"></script>

Now, I've got all the other variables down, but the e-mail address that I need to append under ordernum will be a part of the link generated by aWeber on the thank you page, as such:

http://example.com/welcome?email=johndoe@mailserver.com

Now, aWeber offers this instruction:

https://help.aweber.com/hc/en-us/articles/204027506-How-Do-I-Display-Subscribers-Names-Or-Email-Addresses-On-My-Thank-You-Page-

And I'm sure I can't just go and add this to the url:

http://example.com/idevaffiliate/sale.php?profile=12345&idev_saleamt=123&idev_ordernum=<script type="text/javascript">formData.display("email")</script>

I'm really struggling to find anything relevant online. Any help is more than welcome. Thanks!


Solution

  • Is this what you are looking for?

    //Set email address to variable email
    var email = mail@mail.com;
    
    //Get content (value) of `src`-attribute and put it into src-variable
    var src = $("script[lang='JavaScript']").attr("src");
    
    //Replace VALUE with and put it into newSrc -variable
    var newSrc = src.replace('VALUE',email);
    
    //Check if ok
    console.log(newSrc);
    
    /********/
    /*UPDATE*/
    /********/
    //replace old src with newSrc
    $("script[lang='JavaScript']").attr("src", newSrc);