所有,
我们的客户在网页的头部添加了双击脚本,如下所示
<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>
在添加setTimeout(function(){})之后,如下所示:
<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>
网页刷新,但会显示空白网页。我阅读了帖子here和here,看来document.write在延迟重新加载后清除页面,然后出来使用如下解决方案:
<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>
由于我不确定使用如上所述的parentNode是否正确并替换这样的代码,任何人都可以帮忙检查一下吗?非常感谢