Hi all,

I want to add a canonical to a page that is gerated with my CMS.

For instance, I want to add: <link rel="canonical" href="testURL" /> to my page.

I figured that this possibele using Javascript and tried the following:

<head>
...
<script type="text/javascript">
var head = document.getElementsByTagName('head')[0];
var canonical = document.createElement('link');
canonical.setAttribute('rel','canonical');
canonical.setAttribute('href','testurl');
head.appendChild(canonical);
</script>
...
</head>

Question: Why doesn't this work?

I am not experienced in programming in Javascript, but I have some basic skills.