Older browsers may not support Window.bota
, which is basically an oddly-named method to convert strings to base64 representations, as you probably know.
Making new functionality available in older browsers is called "polyfilling". Put the script base64.js
(download) or base64.min.js
(download) on your website (I'm going to assume you're using the latter, and putting it in the /js/vendor
directory), and reference it thusly (before you need to use Window.bota
):
<script src="/js/vendor/base64.min.js"></script>
If the browser is newer, this script won't do anything (i.e., it won't replace the existing Window.btoa
implementation). If the browser is older, it will now have the functionality.
If you want to avoid the additional HTTP request required to read base64.min.js
, you can use yepnope:
yepnope({
test: window.btoa && window.atob,
nope: '/js/vendor/base64.js',
callback: function () {
// `btoa` and `atob` are now safe to use
}
});