我在博主主题中发现了一个未知的脚本

I found a unknown script in blogger theme

本文关键字:一个 未知 脚本 发现      更新时间:2023-09-26

熟悉博主的人可以告诉我这个脚本在做什么吗?

<script type="text/javascript">
(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//pagead2.googlesyndication.com/pagead/js/google_top_exp.js';
var head = document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(script);
}})();
</script>

我试图查看此文件中的内容//pagead2.googlesyndication.com/pagead/js/google_top_exp.js,但代码被缩小且难以阅读。

我找到了答案。

代码来自博主导航栏。

(function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '//pagead2.googlesyndication.com/pagead/js/google_top_exp.js';
var head = document.getElementsByTagName('head')[0];
if (head) {
head.appendChild(script);
}})();

1) 这是一个匿名的自调用函数。

2) 在此函数中,您正在创建一个脚本元素:

script = document.createElement('script');

3) 为 JS 文件提供一个 SRC:

script.src = '//pagead2.googlesyndication.com/pagead/js/google_top_exp.js';

4)获取元件头:

var head = document.getElementsByTagName('head')[0];

5)然后,如果文档中包含一个head元素,则将脚本元素附加到head中

if (head) {
head.appendChild(script);
}})();

几天前我创建了一个blogspot教育博客,并将其重定向到自定义域。我发表了两篇关于它的博客文章。

有一天,我

正在访问博客,并在网站上打开了广告拦截器,我发现它阻止了 1 个广告。当我将网站列入白名单时,它什么也没显示。

然后,转到"查看源代码"选项。我遇到了你说的同一个脚本。

我很震惊,因为谁希望任何代码在未经任何许可的情况下出现在网站上。然后,我研究了它,并了解到它的代码会自动出现在每个新创建的博客(blogspot博客)上。当您创建博客并且什么都不做(即当您不定期发布时)时,这很可能会出现。

我的主题上的代码位于:

<div id="navbar-iframe-container">

所以,如果你想让它消失,你应该每天发布大约 2-3 个帖子,它早就不复存在了。顺便说一句,即使它在那里,它也不会做任何坏事,也不会在您的博客上显示广告。

它由博客插入。尝试使用主题>"编辑 html"将其从主题中删除,然后保存并刷新脚本将再次出现。我认为这可能是博主本身注入的。当您运行页面时,它通常显示为

window['google_empty_script_included'] = true;

所以它可能用于广告,不应该担心。