My website has the following code structure:
<link rel="amphtml" href="http://example.com/?amp"></head>
I want to extract the html link only on pages where the "amphtml" rel value is present. I attempted this code, but it causes issues on URLs where that tag is not found.
var ampLink_txt = document.querySelector("link[rel=amphtml]").getAttribute("href");
Since I can't modify the HTML document by adding any IDs or classes, could someone guide me in the right direction?