T
T
tester2020-04-21 21:57:47
JavaScript
tester, 2020-04-21 21:57:47

Why doesn't the script work when you open the site locally?

Everything works on the hosting, but when you open the site locally, just through the browser ( file:///C:/addwine/index.html ), this particular script does not work:

$('img.img-svg').each(function(){
  var $img = $(this);
  var imgClass = $img.attr('class');
  var imgURL = $img.attr('src');
  $.get(imgURL, function(data) {
    var $svg = $(data).find('svg');
    if(typeof imgClass !== 'undefined') {
      $svg = $svg.attr('class', imgClass+' replaced-svg');
    }
    $svg = $svg.removeAttr('xmlns:a');
    if(!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
      $svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
    }
    $img.replaceWith($svg);
  }, 'xml');
});

5e9f4200722a4877179152.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2020-04-22
@tokmaganbet

security policy, can be eliminated by a browser plugin, or by running on a local server like nodejs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question