javascript - A better test for base64 URI support (can I create a large base64-encoded image in JS?) -



javascript - A better test for base64 URI support (can I create a large base64-encoded image in JS?) -

i'm using modernizr observe features supported in browser our users running, far good. i've come against theoretical problem when testing base64 compatibility. patch back upwards detailed here, , works- except weird case ie8- it allows base64 encoded images of 32kb.

i don't want embed 32kb long base64 string within js file, it'll add together crazy amount of bloat. so, create 32kb- valid- image using js? i'm thinking repeating kind of pattern within string until reaches 32kb in length, sort of thing. or maybe taking existing tiny string (like 1 in modernizr patch) , adding junk info @ end still results in valid image.

i know next nil base64 encoding, other how manipulate existing image. have ideas?

i think have answer. tried sorts of techniques (repeated text chunks in png source manually add, etc) until found adding line breaks appears job:

var b64test = new image(); b64test.onload = function() { alert("yay!") } b64test.onerror = function() { alert("boo") } /* 1x1 gif image */ var base64str = "r0lgodlhaqabaiaaaaaaap///ywaaaaaaqabaaacauwaow==" while (base64str.length < 33000) { base64str = "\r\n" + base64str; } b64test.src= "data:image/gif;base64," + base64str;

fails in ie8, works in ie9 , others. i'd love hear alternatives, though.

javascript html5 base64 modernizr data-uri

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -