javascript - 我正在尝试在示例 html 中添加 google adsense,但它在控制台中显示错误?

标签 javascript jquery html css adsense

<!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,但没有用。 我在下面附上了控制台的屏幕截图。

/image/558XF.png

最佳答案

您看到此内容的原因是 //pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 行。这是协议(protocol)相关的。

在您的屏幕截图中,您正在从 file:/// 加载 - 它在您的计算机上不存在于它在 httphttps 协议(protocol)。

要解决此问题,请考虑将 src 更改为 https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js 或将其指向相对路径如果您想要加载本地 adsbygoogle.js 文件。

另一种解决方案,如果您在本地安装了 Python,则运行本地网络服务器,并通过 http 而不是 file 协议(protocol)查看您的网站。这可以通过打开终端,cding 到您的桌面,运行 python -m SimpleHTTPServer,然后访问 http://localhost:8000 来完成。在您的浏览器中。

关于javascript - 我正在尝试在示例 html 中添加 google adsense,但它在控制台中显示错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43751951/

相关文章:

JQuery click() 无法正常工作?

javascript - knockout 无法观察到样式属性

javascript - Angular 中的键/值查找

javascript - 如何在 Storybook 中模拟 Next.js Image 组件?

javascript - Google Maps API v3 热图错误 : "Cannot read property ' HeatmapLayer' of undefined"

javascript - 剑道网格 : How to sort (and filter) a column bound to a simple json object

jquery - 使用 jquery 更改背景图像

javascript - IE8 绑定(bind)的 knockout 问题

javascript - 如何从图像数组创建一个非常简单的 jquery 幻灯片?

javascript - HTML 和 JavaScript 中的月份选择下拉菜单