Beispiel:JS-Window-btoa-Unicode.html
Aus SELFHTML-Wiki
<!doctype html>
<html lang="de">
<head>
<title>btoa</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./Beispiel:SELFHTML-Beispiel-Grundlayout.css" />
<script>
document.addEventListener('DOMContentLoaded', function(evt) {
document.getElementById('encu').addEventListener('click', encode);
});
function encode() {
let s = document.getElementById('einu').value;
let uc = new Uint16Array(s.length);
for (let i = 0; i < uc.length; ++i) {
uc[i] = s.charCodeAt(i);
}
document.getElementById('ausu').textContent =
btoa(String.fromCharCode(...new Uint8Array(uc.buffer)));
}
</script>
</head>
<body>
<h1>btoa</h1>
<form>
<p><label>Klartext: <input type="text" id="einu"/></label><p>
<button id="encu" type="button">Encodieren</button>
<p><label>Base64: <output id="ausu"></output></p>
</form>
</body>
</html>