javascript - How to dynamically add links to canonical urls -


i working on project in angular need add dynamic links canonical urls. page changes url in canonical href should change/update.there conditions have added because of parent urls should added. below code:

var url         = window.location.href,     urlsegments = url.split("/").length - 1 - (url.indexof("http://")==-1?0:2);             if(urlsegments <= 7) {                 var link = document.createelement('link');                 link.setattribute('rel', 'canonical');                 link.setattribute('href', url);                 document.head.appendchild(link);             } 

but not working.what wrong doing here , can best solution this. in advance!!

you tagged angulajs tag think should angular way - directive. haven't specified not working hard give details, here have example on how manipulate <head> elements directive.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -