Skip to content

Instantly share code, notes, and snippets.

@3con
Forked from krschmidt/head.html
Created October 17, 2017 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3con/6e28f0be84fe699169fbfa15faac6885 to your computer and use it in GitHub Desktop.
Save 3con/6e28f0be84fe699169fbfa15faac6885 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