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.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.
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 > |
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' ), |
04 |
enc.keyup( function () { |
05 |
dec.val($.base64.btoa( this .value)); |
11 |
dec.keyup( function () { |
13 |
enc.val($.base64.atob( this .value, true )); |
19 |
$( 'textarea' ).on( 'focus blur' , function () { |
20 |
$( this ).prev( 'label' ).stop().fadeToggle(200); |
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 ; |