!DOCTYPE htmlhtmlhead titleBase64 Decodertitleheadbody h1Base64 Decoderh1 label for=inputEnter Base64 Encoded Stringlabelbr input type=text id=inputbrbr button onclick=decodeDecodebuttonbrbr label for
当使用多个atob()函数进行解码时,需要确保输入的Base64编码字符串的长度是4的倍数,否则会导致解码失败。以下是修改后的代码:
Base64 Decoder
<script>
function decode() {
var input = document.getElementById("input").value;
var output = document.getElementById("output");
var padding = '';
if (input.length % 4 !== 0) {
var padCount = 4 - input.length % 4;
padding = Array(padCount + 1).join('=');
}
var decoded = atob(atob(input + padding));
output.value = decoded;
}
</script>
原文地址: https://www.cveoy.top/t/topic/bWpz 著作权归作者所有。请勿转载和采集!