Here is my code:
var some_HTML_string = "<img src='images/relative/path.jpg'>";
console.log("about to call $.parseHTML");
$.parseHTML(some_HTML_string)
console.log("I've just called $.parseHTML");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
In Chrome I'm getting error:
GET file:///C:/Users/mstefanow/Desktop/images/relative/path.jpg net::ERR_FILE_NOT_FOUND
(it doesn't throw this error in IE Edge, IE 11, Firefox 40)
I want to solve it in a way that if any of my clients / stakeholders visit the website there is no red in console...
From related questions:
1) Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js - "This error means that file was not found."
2) Suppress "Failed to load resource: net::ERR_FILE_NOT_FOUND" in Chrome Packaged App - "filter icon at the top of the console, and tick »Hide network messages«"
It's not good enough for me. I know file is not there - I'm $.get'ing some remote HTML file I know that relative paths are not working. Also changing my browser setting will not change behaviour on other people machines.
I tried :
window.onerror = function(e) {
};
I would like to better understand what is happening.
Chrome sees something that resembles an images and tries to load it pro-actively?
Standalone code sample:
https://gist.github.com/stefek99/3245c09869b04ebfe49a
Please hack it in a way that there is no red in console :)
UPDATE:
There were couple questions in the comments so I think we need to establish (reptile brain) that I'm not a threat. Then we can establish whether the question is properly formed / whether I'm doing the right approach.
This is the code I'm using:
$.get("https://test_server", function(data) {
var model_names = $(data).find("li").map(function (index, li) {
return $(li).data("name");
});
var output_html = model_names.map(function (index, name) {
return "<img src='https://test_server/api/preview/" + name + "' data-name='" + name + "'><br>";
})
$("#thumbnails").html(Array.prototype.join.call(output_html, "\n"));
});
https://test_server
serves HTML that contains <li>
nodes that contain required attributes.
I thought it is better to present an isolated test case and focus on the issue. However I appreciate your curiosity, suggestions and questions why I'm doing this that way... (please don't educate me about XSS attacks when concatenating HTML the way I do this right now)