* Determine if exists in the page and * return the href's value iff it starts with http:// or https://. * Otherwise returns empty string. * * @return {string} * @private
()
| 44 | * @private |
| 45 | */ |
| 46 | function getAmpHtmlLinkHref() { |
| 47 | let ampHtmlLinkHref = ''; |
| 48 | // URL must begin with http:// or https:// |
| 49 | const validUrlPrefixRe = /^[\s\xa0]*https?:\/\//; |
| 50 | const headLinks = document.head.getElementsByTagName('link'); |
| 51 | if (headLinks.length > 0) { |
| 52 | for (const index in headLinks) { |
| 53 | const link = headLinks[index]; |
| 54 | if (link instanceof HTMLLinkElement && |
| 55 | link.hasAttribute('rel') && |
| 56 | globals.amphtmlRegex.test(link.getAttribute('rel')) && |
| 57 | link.hasAttribute('href') && |
| 58 | validUrlPrefixRe.test(link.getAttribute('href'))) { |
| 59 | ampHtmlLinkHref = link.getAttribute('href'); |
| 60 | break; |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | return ampHtmlLinkHref; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Determine if the page is from an AMP Cache. |
no test coverage detected