我被要求在我的网站上实现一个 javascript Floodlight 标签,每次客户下载 pdf 文件时都会调用该标签。我尝试按如下方式实现:
<script type="text/javascript">
function appForm() {
var axel = Math.random() + "";
var a = axel * 10000000000000;
document.write('<IFRAME SRC="http://fls.doubleclick.net/activityi;src=1234567;type=count123;cat=123do456;ord=1;num='+ a + '?" WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>');
return false;
}
</script>
<a href="appForm.pdf" target="_blank" onClick="appForm();">Download PDF</a>
这似乎几乎可行。 pdf 文件在新窗口中打开。但您单击下载链接的窗口会变成空白。有没有办法打开这个跟踪 iframe,然后打开 pdf,而父窗口不会变成空白?我们将非常感谢您的帮助。
最佳答案
页面加载后,无法可靠地使用 document.write()。使用更现代的 document.createElement
函数及其 friend :
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "http://...");
iframe.setAttribute("width", "1");
iframe.setAttribute("height", "1");
iframe.setAttribute("frameborder", "0");
document.body.appendChild(iframe);
(未经测试,但似乎应该有效......)
关于Javascript 泛光灯跟踪 iframe 使浏览器窗口空白,请帮忙!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2656683/