Last active
June 29, 2021 18:47
-
-
Save chrisallick/5052009 to your computer and use it in GitHub Desktop.
Base64 in JavaScript turn a json object to a base64 string. boom!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Base64 Demo</title> | |
<meta charset="utf-8"> | |
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' type='text/javascript'></script> | |
<script src='https://javascriptbase64.googlecode.com/files/base64.js' type='text/javascript'></script> | |
<script> | |
var data = {x:"cool"}; | |
$(document).ready(function() { | |
$("#data").submit(function(event){ | |
var e = Base64.encode(JSON.stringify(data)); | |
var d = Base64.decode( e ); | |
// test | |
console.log( data, e, d, JSON.parse( d ) ); | |
//output | |
console.log( "http://dopenach.os/"+e ); | |
return false; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="wrapper"> | |
<form id="data"> | |
<input type="submit" /> | |
</form> | |
</div> | |
</body> | |
</html> |
wow 3 year resurrection 👍
Is there a reason why you've used base64.js instead of the native btoa/atob?
Is there a reason why you've used base64.js instead of the native btoa/atob?
Well... considering I posted this in 2013 I've got to imagine that btoa/atob was either not around or not available in enough browsers. On top of that, I trust a web developer's abstraction over a browser's implementation of a core technology lol.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
unable to find https://javascriptbase64.googlecode.com/files/base64.js
Thanks
Shrikant
shri.bhongade@gmail.com