Skip to content

Instantly share code, notes, and snippets.

@scottoffen
Created July 2, 2014 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottoffen/1e161e0a214fde8011a9 to your computer and use it in GitHub Desktop.
Save scottoffen/1e161e0a214fde8011a9 to your computer and use it in GitHub Desktop.
Base64 Encode/Decode using HTML JavaScript
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Encode/Decode Base64</title>
<style type="text/css">
body
{
margin: 0px;
padding: 0px;
color: #2b2b2b;
background-color: #f2f2f2;
font-family: 'Calibri';
font-size: 10pt;
}
#header
{
position: absolute;
top: 0px;
left: 0px;
right: 0px;
height: 60px;
background-color: #2b2b2b;
color: #f2f2f2;
}
#header h1
{
margin: 0px;
font-family: 'Calibri';
font-size: 16pt;
padding: 20px 20px 20px 20px;
}
#content
{
position: absolute;
top: 60px;
left: 0px;
right: 0px;
}
#content .inner
{
padding: 20px 20px 20px 20px;
}
#content input[type="text"]
{
width: 200px;
}
#content button
{
font-size: 9pt;
}
#content h2
{
margin: 0px;
font-family: 'Calibri';
font-size: 12pt;
padding: 20px 0px 10px 0px;
}
#results a
{
display: block;
}
</style>
<script>
var string, result;
window.onload = function ()
{
string = document.getElementById('string');
result = document.getElementById('result');
string.value = "";
result.innerHTML = "";
};
function Encode ()
{
result.innerHTML += 'String: ' + string.value + '<br><br>' + 'Encoded: ' + window.btoa(string.value) + '<hr>';
string.value = "";
string.focus();
}
function Decode ()
{
result.innerHTML += 'Encoded: ' + string.value + '<br><br>' + 'String: ' + window.atob(string.value) + '<hr>';
string.value = "";
string.focus();
}
</script>
</head>
<body>
<div id="header">
<h1>Base64 String Encode/Decode</h1>
</div>
<div id="content">
<div class="inner">
String : <input type="text" name="string" id="string"> <button onclick="Encode();">Encode</button> <button onclick="Decode();">Decode</button><br>
<h2>Result:</h2>
<div id="result"></div>
</div>
</div>
</body>
</html>
@scottoffen
Copy link
Author

A simple page with no external dependencies you can put anywhere - on your local machine or on a website - that will encode/decode strings using base64. Great for when you want the answer faster than it takes to do a google search for for a site (that will be littered with advertising of unknown repute) that will do this for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment