<pre id="results"></pre> <script> if ('TextDecoder' in window) { // The local files to be fetched, mapped to the encoding that they're using. var filesToEncoding = { 'utf8.bin': 'utf-8', 'utf16le.bin': 'utf-16le', 'macintosh.bin': 'macintosh' }; Object.keys(filesToEncoding).forEach(function(file) { fetchAndDecode(file, filesToEncoding[file]); }); } else { document.querySelector('#results').textCon