【发布时间】:2021-12-23 00:49:00
【问题描述】:
我需要实现
<img src="url" width="1" height="1" style="display:none" />
在 Google 跟踪代码管理器(和你们)的帮助下进入开头。
如何做到这一点?
【问题讨论】:
-
我想说的是:在body中实现img src标签
我需要实现
<img src="url" width="1" height="1" style="display:none" />
在 Google 跟踪代码管理器(和你们)的帮助下进入开头。
如何做到这一点?
【问题讨论】:
Javascript 只允许追加到正文的末尾 - 因此,您必须在正文的第一个孩子之前插入,而不是追加到正文。
创建自定义 HTML 标记,然后插入
<script>
// create the image
var img = document.createElement("img");
// set properties such as a weird example url and style
img.src = "https://www.kukksi.de/wp-content/uploads/2020/05/19-Disney-13-Goofy-und-Max.jpg";
img.style = "display:none";
// insert before the first child element of the body, which will place the element at the beginning of the body
document.body.insertBefore(img, document.body.firstChild);
</script>
我不得不说,很难想象一个有效的用例。
【讨论】: