function Haswebp () { //view cookie, if not, make the following logical var img = new Image (); Img.onload = Handlesupport; Img.onerror = Handlenotsupport; IMG.SRC = ' data:image/webp;base64,uklgrkoaaabxrujqvla4waoaaaaqaaaaaaaaaaaaquxqsasaaaabbxareyii/ gcaaabwudgggaaaadabaj0bkgeaaqababwlpaadcad+/gbqaa== '; Otherwise execute handlesupport or handlenotsupport}function handlesupport ( ' swebp ', ' true ', 2592000) according to the cookie; /30 days expires}function Handlenotsupport () { Setcookie (' Swebp ', ' false ', 2592000);}
The following is the Localstorage version
function Detectwebp () { if (!window.localstorage | | typeof localstorage!== ' object ') return; var name = ' WEBPA '; WEBP available if (!localstorage.getitem (name) | | (Localstorage.getitem (name)!== ' available ' && localstorage.getitem (name)!== ' disable ')) { var img = document.createelement (' img '); Img.onload = function () { try { localstorage.setitem (name, ' available '); } catch (ex) { } }; Img.onerror = function () { try { localstorage.setitem (name, ' Disable '); } catch (ex) { } };< C16/>IMG.SRC = ' data:image/webp;base64,uklgrkoaaabxrujqvla4waoaaaaqaaaaaaaaaaaaquxqsasaaaabbxareyii/ gcaaabwudgggaaaadabaj0bkgeaaqababwlpaadcad+/gbqaa== '; }}
WEBP practice of JavaScript detection scheme