Created
October 25, 2016 15:29
-
-
Save ashhitch/a3fa1c62eb848c93cc973b69f6ef3381 to your computer and use it in GitHub Desktop.
Get Page URL from canonical tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Get page url | |
| let url = document.location.href; | |
| //Get canonical | |
| const canonicalEl = document.querySelector('link[rel=canonical]'); | |
| //if canonical tag present replace url | |
| if(canonicalEl !== undefined) { | |
| url = canonicalEl.href; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment