sawmac / display-markdown

JS Rendering of Markdown Files
29 stars 16 forks source link

Catching when "README.md" does not exist #4

Open TedThompson opened 3 years ago

TedThompson commented 3 years ago
var xhr = new XMLHttpRequest();
xhr.onloadedend = function () {
    if(xhr.status == 404) return;
    }
xhr.onreadystatechange = function () {

First and last lines already exist - I inserted this function. I am using your "index.html" renamed as the src for an IFRAME in my index.html. It's a header for the index in every folder on my site, and will display the Readme.md as a MOTD - but I needed to avoid a 404 error if there was no Readme.md.

I also added

    <script>
      var path = document.referrer;
      var motd = "Readme.md";
      var file = path.concat(motd);
    </script>

to your original HTML, so it looks for the Readme.md in the same directory as the parent page.