如何在AMP页面上的每个标签上附加查询字符串?

问题描述 投票:0回答:1

我正在尝试将查询字符串附加到AMP页面上的每个链接。以下是我的代码:JavaScript代码:

var a = document.getElementsByTagName('a'),length = a.length;

for(var i=0; i< length; i++){
  a[i].href += '?key=value';
}
HTML代码:
<amp-script layout="container" src="https://example.com/custom.js">
</amp-script>
amp脚本如何工作。我使用的对吗?脚本不起作用。
javascript amp-html
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.