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
Post a Comment