I'm using this script to check for support for webp
images but I'm having trouble setting the type, here's the code that checks:
hasWebP = (function() {
var images = {
basic: "data:image/webp;base64,UklGRjIAAABXRUJQVlA4ICYAAACyAgCdASoCAAEALmk0mk0iIiIiIgBoSygABc6zbAAA/v56QAAAAA==",
lossless: "data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA="
};
return function(feature) {
var deferred = $.Deferred();
$("<img>").on("load", function() {
if(this.width === 2 && this.height === 1) {
deferred.resolve();
} else {
deferred.reject();
}
}).on("error", function() {
deferred.reject();
}).attr("src", images[feature || "basic"]);
return deferred.promise();
}
})();
hasWebP().then(function() {
tipo = "webp";
}, function() {
tipo = "jpg";
});
console.log(tipo);
But when I call the variable tipo
out of this function it is given as undefined
.
I've tried to create it so window.tipo
but it also did not work, how can I solve this problem?