问题
I need base64 decode script.
I have for example:
var windowWidth = $( window ).width();
var windowHeight = $( window ).height();
var documentWidth = $( document ).width();
var documentHeight = $( document ).height();
I use this online plugin: Base64 Decode Encode Plugin and result from this plugin is:
ICAgIHZhciB3aW5kb3dXaWR0aCA9ICQoIHdpbmRvdyApLndpZHRoKCk7CiAgICB2YXIgd2luZG93SGVpZ2h0ID0gJCggd2luZG93ICkuaGVpZ2h0KCk7CiAgICB2YXIgZG9jdW1lbnRXaWR0aCA9ICQoIGRvY3VtZW50ICkud2lkdGgoKTsKICAgIHZhciBkb2N1bWVudEhlaWdodCA9ICQoIGRvY3VtZW50ICkuaGVpZ2h0KCk7Cg==
How to use this result in jquery.
回答1:
You can use window.btoa(string) to encode any string, and window.atob(string) to decode it.
In your case
window.atob('ICAgIHZhciB3aW5kb3dXaWR0aCA9ICQoIHdpbmRvdyApLndpZHRoKCk7CiAgICB2YXIgd2luZG93SGVpZ2h0ID0gJCggd2luZG93ICkuaGVpZ2h0KCk7CiAgICB2YXIgZG9jdW1lbnRXaWR0aCA9ICQoIGRvY3VtZW50ICkud2lkdGgoKTsKICAgIHZhciBkb2N1bWVudEhlaWdodCA9ICQoIGRvY3VtZW50ICkuaGVpZ2h0KCk7Cg');
Returns
" var windowWidth = $( window ).width();
var windowHeight = $( window ).height();
var documentWidth = $( document ).width();
var documentHeight = $( document ).height();
"
Which is just one string with four linebreaks.
If you want to use them to declare variables in your current scope, one way would be to split by linebreaks and then eval each line, but using eval is a bad idea in general.
I suggest you reconsider what do you want to achieve and find a safer method.
来源:https://stackoverflow.com/questions/28321091/how-to-use-decode-jquery-script