Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 22nd, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function utf8_to_b64( str ) {
  2.     return window.btoa(unescape(encodeURIComponent( str )));
  3. }
  4.  
  5. function b64_to_utf8( str ) {
  6.     return decodeURIComponent(escape(window.atob( str )));
  7. }
  8.  
  9. Modernizr.load({
  10.     test: window.btoa && window.atob,
  11.     nope: 'base64.js',
  12.     complete: function () {
  13.         var encodedData = utf8_to_b64("Hello, world"); // encode a string
  14.         var decodedData = b64_to_utf8(encodedData); // decode the string
  15.     }
  16. });