我不想再为每个html文件写同样的代码。有没有办法让下面的代码可以在所有的html页面上使用。
<script async src="https://www.googletagmanager.com/gtag/js?id="></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', '');
</script>
<meta charset="UTF-8">
<link rel="icon" href="icon.png">
etc...
我的意思是,例如,在每个html页面上复制head.txt的代码。这将允许我不在所有的页面上写同样的代码片段。
你的问题非常难以理解,但我将尝试。
文件连接使用
<link rel = "import">
:
<head>
<link rel = "import" href = "/ path / to / imports / stuff.html">
</head>
指定的URL是导入位置。要使用从其他域导入,其位置必须允许跨域资源共享(CORS)。
<! - Resources on other origins must be CORS-enabled. ->
<link rel = "import" href = "http://example.com/elements.html">
注意:浏览器会忽略对同一URL的重复请求。这意味着无论页面上有多少个连接,从一个地址只能进行一次下载。