How to use Base64 transcoding in JavaScript
Let str = ' javascript '; Let btoastr = Window.btoa (str); transcoding results amf2yxnjcmlwda== Console.log (BTOASTR); Console.log (Window.atob (BTOASTR)); Decoding results JavaScript
The Base64 transcoding object can only be a string,
var str = "China, Chinese"; Window.btoa (str);
Error uncaught domexception:failed to execute ' btoa ' in ' Window ': the string to be encoded contains characters outside of The Latin1 range.
So how do we get him to support Chinese characters?
Let str = ' javascript, blog '; let btoastr = Window.btoa (window.encodeuricomponent (str)); transcoding results Amf2yxnjcmlwdcuyqyvfnsu4rcu5qsvfnsvbrsvbmg==console.log (BTOASTR);
Console.log (Window.decodeuricomponent (Window.atob (BTOASTR))); Decoding results JavaScript, Blogs
This is the simple and practical btoa and Atob, I hope to be helpful to everyone.
JavaScript uses Btoa and Atob for Base64 transcoding and decoding