Javascript: Check link does not exist or expired

 

    async function fetchLinks(content) {

      // create blog content obj

      var contentObj = document.createElement('div');

      contentObj.innerHTML = content;

      var links = contentObj.getElementsByTagName('a');

      for(var i = 0; i < links.length; i++){

        // nodes[i].parentNode.removeChild(nodes[i]);

        try {

          const href = links[i].getAttribute('href');

          const request = new Request(href, {

            method: "HEAD",

          });

          const response = await fetch(request);

          // waits until the request completes...

          if (response.status == '410' || response.status=='400') {

            console.log(href);

          }

        } catch (error) {

          // console.log(error);

        }


      }


    }


Không có nhận xét nào:

StaticImage

  import React , { useEffect , useRef } from "react" import { StaticImage } from "gatsby-plugin-image" impor...