I try to make a simple page with random url using javascript in amp page, but it doesn't work, can anyone help me please. this code work normaly with "script" tag, but I need to make it work in amp page
this is the example code:
<html amp lang="id">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="robots" content="index, follow"/>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
</head>
<body>
<div>
<p>
<a title="search-engine" href="/" target="_blank" rel="noopener noreferrer" class="random">click here</a> for random search engine
</p>
</div>
<amp-script src="https://xn4gq0a0f40a7o26m8zyn4betxs3bz4ix5ojt6aphbt8ke22.vip/testrandom.js"></amp-script>
</body>
</html>
and this is the js:
function getUrlweb()
{
var urlweb = [
'https://www.google.com/',
'https://www.yahoo.com/',
'https://yandex.com/',
'https://duckduckgo.com/',
];
return urlweb[Math.floor(Math.random() * urlweb.length)];
}
const curlweb = document.getElementsByClassName("random");
for (let i = 0; i < curlweb.length; i++) {
curlweb[i].href = getUrlweb();
}
the code is working perfectly in non amp page but I need to make it work in amp page so I use "amp-script" tag and it's not working