Hack Forums
[Help] Print Javascript in img src - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: [Help] Print Javascript in img src (/showthread.php?tid=5941334)



Print Javascript in img src - Grey Goose - Feb 15, 2019

Hi,

I'm working on a tracking mechanism to a affiliate script and need a unique ID in my src.

I have the following code:

Code
<script type="text/javascript">
    function uuidv() {
  return 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}

document.write(uuidv());
</script>

<img src="https://www.partner-ads.com/dk/leadtrack.php?programid=xxxx&type=lead&uiv=VAR HERE" width=0 height=0 style="display:none">

I need the uuidv()) function to be inserted into the src where it says VAR HERE - How the f... do i do that?


RE: Print Javascript in img src - I337 - Feb 15, 2019

Do you have access to the js on the same page??
I think you need to use onclick and change the src and add UUID


RE: Print Javascript in img src - Grey Goose - Feb 15, 2019

(Feb 15, 2019 07:56 AM)thelastone1 Wrote:  Do you have access to the js on the same page??
I think you need to use onclick and change the src and add UUID

I don't think onclick is an option.

The script is going to be on a "succes page" from when you're signing up for a newsletter.


RE: Print Javascript in img src - Abruptum - Feb 15, 2019

(Feb 15, 2019 08:14 AM)Grey Goose Wrote:  I don't think onclick is an option.

The script is going to be on a "succes page" from when you're signing up for a newsletter.

I think it would be better to generate the ids server side or there will be duplicates.

Possible Solution without server side checking:
Code
<img id="partner-ads" src="" width=0 height=0 style="display:none">
<script type="text/javascript">
    var programid = "";
    var uuid = "";
    function uuidv() {
        return 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
            return v.toString(16);
        });
    }
    uuid = uuidv();
    document.getElementById("partner-ads").src = `https://www.partner-ads.com/dk/leadtrack.php?programid=${programid}&type=lead&uiv=${uuid}`;
</script>