0

all,

Our client has doubleclick script added in the head of the web page like below,

<head>
...
<script type="text/javascript">
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.write('<iframe src="https://....doubleclick.net/activityi;src=...;...ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
</script>
</head>

And after add the setTimeout(function(){}) as below:

<head>
...
<script type="text/javascript">
var delay=10000;
setTimeout(function(){
        var axel = Math.random() + "";
        var a = axel * 10000000000000;
        document.write('<iframe src="https://....doubleclick.net/activityi...ord=' + a + '?" width="1" height="1" frameborder="0" style="display:none"></iframe>');
    },delay)
</script>
</head>

The web page refresh, but gives a blank web page. I read the post here and here, and it seems document.write wipes out the page after a delay reload, and then come out to use the solution as below:

<head>
...
<script>
setTimeout(function(){
            var iframe = document.createElement('iframe');
            var axel = Math.random() + "";
            var a = axel * 10000000000000;
            iframe.src = 'https://....doubleclick.net/activityi;...ord=' + a + '?';
            iframe.width = 1;
            iframe.height = 1;
            iframe.frameborder = 0;
            var ref = document.getElementsByTagName('script')[0];
            ref.parentNode.insertBefore(iframe, ref);
            }, delay)
</script>
</head>

As I not sure whether it is correct to use parentNode as above and replace the code like this, can any one help to check? Thanks very much

Community
  • 1
  • 1
zhihong
  • 1,808
  • 2
  • 24
  • 34
  • Two questions: why is this on a timeout/ wouldn't it be better off just below your `

    `, and secondly: why is there a variable being added to this scripts _before_ the `?` argument delimiter of a URL and why is it so randomised (and why is it converted to a string using `+ ''` = that seems wrong)?

    – somethinghere Oct 12 '15 at 11:26
  • @somethinghere, thanks for your quick reply. As original script from client put the doubleclick script in the head, that is why I had it in the head. Dose timeout thing is better in ? The variable is from the default doubleclick code, may be for specific usage, that is why I keep it. And for the src string, it is a way to get the new url, is it wrong? – zhihong Oct 12 '15 at 11:46
  • I think you dont need the timeout if you place it before your closing `

    `. The variable _does not_ look like 'default' doubleclick code, tbh. Try to get the original code back from doubleclick or ask around if anyone has the script you need, and simply paste that before your closing body, as traditional.

    – somethinghere Oct 12 '15 at 11:48

0 Answers0