Skip to content

Instantly share code, notes, and snippets.

@ashhitch
Created October 25, 2016 15:29
Show Gist options
  • Select an option

  • Save ashhitch/a3fa1c62eb848c93cc973b69f6ef3381 to your computer and use it in GitHub Desktop.

Select an option

Save ashhitch/a3fa1c62eb848c93cc973b69f6ef3381 to your computer and use it in GitHub Desktop.
Get Page URL from canonical tag
//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