-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageRequest.js
45 lines (33 loc) · 1.19 KB
/
imageRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function imgLoad(url) {
'use strict';
return new Promise(function (resolve, reject) {
var request = new XMLHttpRequest();
request.open('GET', url);
request.responseType = 'blob';
request.onload = function () {
if (request.readyState === 4 && request.status === 200) {
resolve(request.response);
} else {
reject(new Error('The image didn\'t load successfully; error code: ' + request.statusText));
}
};
request.onerror = function () {
reject(new Error('There was a network error.'));
}
request.send();
});
};
function loadImage() {
'use strict';
var body = document.querySelector('body'),
myImage = new Image();
myImage.crossOrigin = "";
imgLoad('https://cdn.cloudflare.steamstatic.com/steam/apps/1237320/header.jpg?t=1668134681').then(function (response) {
var imageURL = window.URL.createObjectURL(response);
myImage.src = imageURL;
body.appendChild(myImage);
}, function (Error) {
console.log(Error);
});
}
loadImage();