Always can't remember these two functions, simply write down, better turn.
Avascript Native API was originally supported, Base64, but due to the limitations of the previous JavaScript, resulting in Base64 basic see useless. When the current HTML5 standard is formalized, BASE64 will have a larger transformation space, which can be implemented for HTML5 APIs such as FileReader API, drag-and-drop uploads, and even canvas,video.
Well, before saying a lot, developers need to focus on:
Let's take a look at how to use the Base64 transcoding in JavaScript
' JavaScript '; Window.btoa (str) "amf2yxnjcmlwda=="Window.atob ("amf2yxnjcmlwda==")"JavaScript "
Two. For transcoding, the Base64 transcoding object can only be a string, so for other data there is a certain limitation, in particular, it is important to note that Unicode transcoding.
"Window.btoa, China"(str)
Uncaught domexception:failed to execute ' btoa ' in ' Window ': the string to be encoded contains characters outside of the L Atin1 range.
Obviously, this way is not possible, then how to let him support the Chinese character, which will use Window.encodeuricomponent and window.decodeuricomponent
"Chinese, China"; Window.btoa (window.encodeuricomponent (str))//"q2hpbmelruylqkmloemlrtqlqjglquqlrtulouilqkq=" window.decodeuricomponent (window.atob (' q2hpbmelruylqkmloemlrtqlqjglquqlrtulouilqkq= '))//" China, "
JavaScript uses Btoa and Atob for Base64 transcoding and decoding