我正在尝试将查询字符串附加到AMP页面上的每个链接。以下是我的代码:JavaScript代码:
var a = document.getElementsByTagName('a'),length = a.length;
for(var i=0; i< length; i++){
a[i].href += '?key=value';
}
<amp-script layout="container" src="https://example.com/custom.js">
</amp-script>
AMP框架通过组件支持自定义脚本。这是示例
<!doctype html>
<html>
<head>
<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
<body>
<amp-script layout="container" src="https://example.com/your_scripts.js">
<p>Any content that can be modified from javascript</p>
</amp-script>
</body>
</html>
允许所有事件触发器
AMP文档
https://amp.dev/documentation/guides-and-tutorials/develop/custom-javascript/?format=websites