Javascript 泛光灯跟踪 iframe 使浏览器窗口空白,请帮忙!

发布于 2024-08-29 08:56:43 字数 630 浏览 4 评论 0原文

我被要求在我的网站上实现一个 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,而父窗口不会变成空白?非常感谢您的帮助。

I have been asked to implement a javascript floodlight tag onto my site which is to be called everytime a customer downloads a pdf file. I have tried to implement this as follows:

<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>

This seems to almost work. The pdf file opens in a new window. But the window where you clicked the download link turns blank. Is there a way of opening this tracking iframe and then having the pdf opening without the parent window going blank? Your help will be very much appreciated on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别挽留 2024-09-05 08:56:43

页面加载后,无法可靠地使用 document.write()。使用更现代的 document.createElement 函数及其朋友:(

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);

未经测试,但似乎应该可以工作......)

document.write() can't be reliably used after the page has loaded. Use the more modern document.createElement function and its friends:

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);

(untested, but seems like it should work...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文