var a =document.getElementsByTagName("link")[0].getAttribute("href");
getElementsByTagName() creates an array of such elements (even though you only have one). It is not like getElementById where there is only one possible element with that attribute. You have to specify which one.