<!DOCTYPE html>
<html>
<head>
This is the head of your page.
<title>Example HTML page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
This is the body of your page.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- horizontal ad -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1677523677681098"
data-ad-slot="1902657162"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
This is the body of your page.
</body>
</html>[enter image description here][1]
它显示 ERR:FILE NOT FOUND。 我使用过本地 adsgoogle.js,但没有用。 我在下面附上了控制台的屏幕截图。
最佳答案
您看到此内容的原因是 //pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 行
。这是协议(protocol)相关的。
在您的屏幕截图中,您正在从 file:///
加载 - 它在您的计算机上不存在于它在 http
或 https
协议(protocol)。
要解决此问题,请考虑将 src
更改为 https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
或将其指向相对路径如果您想要加载本地 adsbygoogle.js
文件。
另一种解决方案,如果您在本地安装了 Python,则运行本地网络服务器,并通过 http
而不是 file
协议(protocol)查看您的网站。这可以通过打开终端,cd
ing 到您的桌面,运行 python -m SimpleHTTPServer
,然后访问 http://localhost:8000 来完成。在您的浏览器中。
关于javascript - 我正在尝试在示例 html 中添加 google adsense,但它在控制台中显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751951/