drupal - drupal_add_html_head 就在 drupal_add_js 之后
问题描述
我想在外部添加 cookiebot 脚本
<script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid="idcookiebot" data-culture="languageId" type="text/javascript"></script>
就在这之后
drupal_add_js("window.dataLayer = window.dataLayer || [];
function gtag() { window.dataLayer.push(arguments); }
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 500,
});",
array('type' => 'inline')
);
但是,使用 drupal_add_html_head,外部脚本位于第一行,但我需要在脚本之后使用它。
我找不到 drupal_add_js 如何使用数据元素添加外部 JS
解决方案
您可以像这样设置scope
额外weight
的javascript:
drupal_add_js("window.dataLayer = window.dataLayer || [];
function gtag() { window.dataLayer.push(arguments); }
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 500,
});",
array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 5,
)
);
推荐阅读
- angular - 处理两个 HTTP 请求(Angular + RxJS)
- javascript - 所有返回 Promise 的函数都必须定义为异步吗?
- python - 在进行转换时跟踪 PIL 图像中的参考像素
- postgresql - 如何在特定范围之间选择日期,包括 PostgreSQL 提供范围之外的最接近可用日期?
- protocol-buffers - 如何只为导入路径生成 protobuf 消息?
- nginx - Nginx SSL Chrome ERR_HTTP2_PROTOCOL_ERROR
- tailwind-css - 如何在tailwindcss中使用2个按钮取消和保存右对齐的页脚
- libreoffice - 使用两列运行总计
- html - 如何在简单的html中制作子页面?
- oracle - 使用 oracle 删除 Toad 弹出窗口中未识别的绑定变量