JavaScript uses Btoa and Atob for Base64 transcoding and decoding

Source: Internet
Author: User
Tags base64

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

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.