Fratozzi Posted March 18, 2020 Share Posted March 18, 2020 I am using this function in js to check if the browser supports the webp images format, if it is compatible, release the image in webp, in png. It works with all browsers but if I try it with mobile safari ios 13 it doesn't work I can't understand where is the problem can you help me? JS var WebpDetect = function() { var onComplete = null; var numFeaturesTested = 0; var features = [ { name: 'lossy', testImage: "UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA" }, { name: 'lossless', testImage: "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA==" }, { name: 'alpha', testImage: "UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==" }, { name: 'animation', testImage: "UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA" } ]; var testFeatureSupport = function(feature, callback) { var image = new Image(); image.onload = function () { var isSupported = image.width > 0 && image.height > 0; callback(feature, isSupported); }; image.onerror = function () { callback(feature, false); }; image.src = "data:image/webp;base64," + feature.testImage; } var onFeatureTested = function(feature, isSupported) { var featureClass = (!isSupported ? 'no-' : '') + 'webp-' + feature.name; $('html').addClass(featureClass); var featureAttribute = featureClass + '-src'; $('img[' + featureAttribute + ']').each(function (index, item) { var imageSource = $(item).attr(featureAttribute); $(item).removeAttr(featureAttribute); if (!isSupported) imageSource = imageSource.substring(imageSource.length - 3) + 'png'; $(item).attr('src', imageSource || ""); }); if (onComplete) { numFeaturesTested++; if (numFeaturesTested == features.length) { onComplete(); } } } return { init: function (parameters) { onComplete = parameters && parameters.onComplete; for (var index = 0; index < features.length; ++index) { testFeatureSupport(features[index], onFeatureTested); } } } }(); HTML <img webp-animation-src="/img/test.webp"> <script src="webp-detect.js" type="text/javascript"></script> <script> $('document').ready(function(){ WebpDetect.init(); }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/310316-webp-detect-js/ Share on other sites More sharing options...
Strider64 Posted March 19, 2020 Share Posted March 19, 2020 The first place I would go to is this website https://caniuse.com/ Quote Link to comment https://forums.phpfreaks.com/topic/310316-webp-detect-js/#findComment-1575600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.