/

HTML / CSS / JavaScript Tutorial

JavaScript Window method: atob()

[this page | pdf | back links]

The atob() method (when applied to Window objects in the JavaScript BOM) decodes a base-64 encoded string (encoded using the btoa() method.

 

It has the following syntax with the following parameters. It returns the decoded string.

 

window.atob(str)

 

Parameter

Required / Optional

Description

str

Required

String which has been encoded using the btoa() method

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td,tr,caption {border: thin solid black; border-collapse: collapse;}
</style>
</head>
<body>
base-64 encoding and decoding:<br><br>
<table>
<tr><td><span id="x1"></span></td>
  <td>encodes to</td><td><span id="y1"></span></td></tr>
<tr><td><span id="x2"></span></td>
  <td>decodes to</td><td><span id="y2"></span></td></tr>
</table>

<script>
var x1 = "?qr";
var y1 = window.btoa(x1);
var x2 = y1;
var y2 = window.atob(x2);
document.getElementById("x1").innerHTML = x1;
document.getElementById("y1").innerHTML = y1;
document.getElementById("x2").innerHTML = x2;
document.getElementById("y2").innerHTML = y2;
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodWindowAtob() {
  return !!window.atob;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile