Skip to content

Instantly share code, notes, and snippets.

@blueprintmrk
Forked from krschmidt/head.html
Created February 20, 2019 22:38
Show Gist options
  • Select an option

  • Save blueprintmrk/28c89f18d7e587f936af98c70636db4e to your computer and use it in GitHub Desktop.

Select an option

Save blueprintmrk/28c89f18d7e587f936af98c70636db4e to your computer and use it in GitHub Desktop.
Set Canonical URL via Javascript
<script type='text/javascript'>
var link = document.createElement('link');
link.setAttribute('rel', 'canonical');
link.setAttribute('href', location.protocol + '//' + location.host + location.pathname);
document.head.appendChild(link);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment