var linkTag = document.createElement ("link"); linkTag.rel = "canonical"; linkTag.href = "www.google.com"; var head = document.getElementsByTagName ("head")[0]; head.appendChild (linkTag);
I have added above code it give me output as <link rel="canonical" href="www.google.com">
but I want to close link tag <link rel="canonical" href="www.google.com" />
like this.
You don't need to generate the closing tag because it's already there. The browser has already taken your text-based HTML and turned it into a tree of nodes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.