admin管理员组文章数量:1323317
using something along the lines of:
background:url(data:image/gif;base64,R0lGODlhIwAhALMAAAAAADQ0NENDQ25ubouLi6ioqLa2ttPT0/Dw8P///wAAAAAAAAAAAAAAAAAAAAAAACwAAAAAIwAhAAAIpQABCBxIsCCAAAYTKlw4cECCAQwjMnSY4KHEiwQpVrSIUaLGjRw7Kvy4EYEAkSNBljyJ0iDJiiZbulQJk6XMhjQTxLyJk+ZOngBe6rTJU+jPojmTKqXZc6nTpAKFPp0qsMDUqyoHWsWKleBWrk8LfgV5AKjYnGXNakWrdi3NtG3HbjTQtmrOAnUByK2It+7eBH3j5iSQVy5cv3PzegWsuCDExmYDAgA7) no-repeat center center;}
is fine but I want to be able to provide graceful degradation (the css assertion is through javascript) when base64 is not available.
obviously, IE prior to v8 lacks this functionality so I could go by browser - but i'd prefer to have it feature detected, if possible.
any ideas on how do go about doing it?
using something along the lines of:
background:url(data:image/gif;base64,R0lGODlhIwAhALMAAAAAADQ0NENDQ25ubouLi6ioqLa2ttPT0/Dw8P///wAAAAAAAAAAAAAAAAAAAAAAACwAAAAAIwAhAAAIpQABCBxIsCCAAAYTKlw4cECCAQwjMnSY4KHEiwQpVrSIUaLGjRw7Kvy4EYEAkSNBljyJ0iDJiiZbulQJk6XMhjQTxLyJk+ZOngBe6rTJU+jPojmTKqXZc6nTpAKFPp0qsMDUqyoHWsWKleBWrk8LfgV5AKjYnGXNakWrdi3NtG3HbjTQtmrOAnUByK2It+7eBH3j5iSQVy5cv3PzegWsuCDExmYDAgA7) no-repeat center center;}
is fine but I want to be able to provide graceful degradation (the css assertion is through javascript) when base64 is not available.
obviously, IE prior to v8 lacks this functionality so I could go by browser - but i'd prefer to have it feature detected, if possible.
any ideas on how do go about doing it?
Share edited Nov 25, 2009 at 15:30 Dimitar Christoff asked Nov 25, 2009 at 13:19 Dimitar ChristoffDimitar Christoff 26.2k8 gold badges51 silver badges69 bronze badges3 Answers
Reset to default 6This might be what you are looking for : http://weston.ruter/2009/05/07/detecting-support-for-data-uris/
I worked on a script that adds a partial support of the DataURI scheme in IE6+ : http://phenxdesign/projects/phenx-web/iedatauri/example.php and the code is here : http://code.google./p/phenx-web/source/browse/trunk/iedatauri/
IE5+ supports a sort of data URI too, it is but not always possible to use it : http://www.betalon./blog/html_css/data-uri-in-css-crossbrowser.htm
Using the above to extend the mootools Browser.Features object (if anyone finds it useful, modernizr does not support it)
http://www.jsfiddle/dimitar/5JT45/13/show/ or https://gist.github./821370
(function() {
Browser.Features.base64 = null;
var callback = function() {
Browser.Features.base64 = this.width == 1 && this.height == 1;
// alert(Browser.Features.base64); // true || false
};
var img = new Image(), img = document.id(img) || new Element("img");
img.onload = img.onerror = img.onabort = callback;
// 1x1 px gif to test with
img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
})();
Found this plugin for Modernizr on their wiki https://github./Modernizr/Modernizr/issues/14:
Modernizr.addTest('datauri',function(){
var data = new Image();
data.onload = data.onerror = function(){
return (this.width == 1 && this.height == 1);
}
data.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
})
本文标签: javascriptis there a viable way to feature detect support for imagedata base64Stack Overflow
版权声明:本文标题:javascript - is there a viable way to feature detect support for image:data base64 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742140869a2422572.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论