base64 decoder encoder - Free Download Base64 Decoder and Encoder In jQuery - base64.js

Free Download Base64 Decoder and Encoder In jQuery – base64.js

Posted on

This time I will share jQuery Plugin and tutorial about Base64 Decoder and Encoder In jQuery – base64.js, hope it will help you in programming stack.

base64 decoder encoder - Free Download Base64 Decoder and Encoder In jQuery - base64.js
File Size: 7.15 KB
Views Total: 571
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

base64.js is a jQuery plugin that helps create an online Base64 decoder and encoder app to encode and decode Base64 data on the client-side.

How to use it:

1. Create textarea elements for the Base64 decoder and encoder.

1 <form>
2   <label for="encode" class="encode">Encode</label>
3   <textarea id="encode">jQueryScript</textarea>
4   <label for="decode" class="decode">Decode</label>
5   <textarea id="decode">alF1ZXJ5U2NyaXB0</textarea>
6 </form>

2. Place jQuery JavaScript library and the jquery.base64.js script at the bottom of the webpage.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="/path/to/jquery.base64.js"></script>

3. The main JavaScript to activate the Base64 decoder and encoder.

01 var dec = $('#decode'),
02     enc = $('#encode');
03  
04 enc.keyup(function () {
05     dec.val($.base64.btoa(this.value));
06     // also possible:
07     // dec.val( $.base64('encode', this.value) );
08     // dec.val( $.base64.encode(this.value) );
09 });
10  
11 dec.keyup(function () {
12     // note: you can pass a third parameter to use the utf8 en- / decode option
13     enc.val($.base64.atob(this.value, true));
14     // also possible:
15     // dec.val( $.base64('decode', this.value) );
16     // dec.val( $.base64.decode(this.value) );
17 });
18  
19 $('textarea').on('focus blur', function () {
20     $(this).prev('label').stop().fadeToggle(200);
21 });

4. You can set utf8 encoding and decoding via global options:

  • utf8encode – utf8 encoding only
  • utf8decode – utf8 decoding only
  • raw – both (default: true)
1 $.base64.utf8encode = true;