-2

Working in HTML/SCSS/JQUERY.

Want to link to a webpage but if it's a broken link that it will load the saved .mht version.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

1 Answers1

0

Another user provided this code in other thread of this forum to chek if a link is broken (JavaScript/jQuery check broken links)

function urlExists(url, callback) {
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {
    if (xhr.readyState === 4) {
      callback(xhr.status < 400);
    }
  };
  xhr.open('HEAD', url);
  xhr.send();
}

  urlExists(someUrl, function(exists) {
  console.log('"%s" exists?', someUrl, exists);
Community
  • 1
  • 1
Fernando Madriaga
  • 438
  • 1
  • 6
  • 17