radiodraws
3/7/2018 - 4:45 PM

load svg safe as xml and inject it in html

load svg safe as xml and inject it in html

    function loadSvg(selector, url) {
      console.log('kshd')
      var target = document.getElementById(selector);

      // If SVG is supported
      if (typeof SVGRect != "undefined") {
        // Request the SVG file
        var ajax = new XMLHttpRequest();
        ajax.open("GET", url + ".svg", true);
        ajax.send();

        // Append the SVG to the target
        ajax.onload = function(e) {
          target.innerHTML = ajax.responseText;
        }
      } else {
        // Fallback to png
        target.innerHTML = "<img src='" + url + ".svg' />";
      }
    }