Warning: Undefined array key "action" in /home/bakers/html/entryreply.php on line 5

Warning: Undefined variable $output in /home/bakers/html/entryreply.php on line 50

Warning: Undefined array key "EntrySubject" in /home/bakers/html/entryreply.php on line 51

Warning: Undefined variable $logintext in /home/bakers/html/entryreply.php on line 97

Warning: Undefined variable $reply_name in /home/bakers/html/entryreply.php on line 103

Warning: Undefined variable $reply_email in /home/bakers/html/entryreply.php on line 104
Perturb.org - interesting technology related things from around the internet

Browser base64 support

Firefox, Chrome, Safari, and Opera have native support for base64 encoding in javascript in the form of the btoa() function. Unfortunately Internet Explorer does not support this, so it's not safe to rely on. There are many base64 javascript libraries you can use though, the performance is just lower. You can do a hybrid solution however, where the browser will use the native btoa() function if it is available, and if not fall back to the javascript implementation. This uses the javascript typeof() function to determine if the native btoa() function is available:

function hybrid_encode(txt) {
    if (typeof(btoa) === 'function') {
        return btoa(txt);
    } else {
        return Base64.encode(txt);
    }
}

I wrote up a test case on jsperf.com to compare the result the results.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 18.212.120.195
To prevent spam please submit by clicking the kitten: