项目作者: tltary

项目描述 :
Remove cyclic links JS
高级语言: HTML
项目地址: git://github.com/tltary/remove-cyclic-links.git
创建时间: 2019-05-16T09:37:07Z
项目社区:https://github.com/tltary/remove-cyclic-links

开源协议:

下载


Remove cyclic links JS

Takes all links from the page and replaces with span to avoid seo looping.

Demo

  1. let link = document.querySelectorAll('a');
  2. let url = window.location.href;
  3. for (let i = 0;i < link.length;i = i + 1) {
  4. if (url == link[i].href) {
  5. replaceTag(link[i]);
  6. }
  7. }
  8. function replaceTag(element)
  9. {
  10. let elementNew = document.createElement('span');
  11. elementNew.innerHTML = element.innerHTML;
  12. Array.prototype.forEach.call(element.attributes, function(attr) {
  13. elementNew.setAttribute(attr.name, attr.value);
  14. });
  15. element.parentNode.insertBefore(elementNew, element);
  16. element.parentNode.removeChild(element);
  17. return elementNew;
  18. }