How to use decode jquery script

雨燕双飞 提交于 2019-12-08 04:07:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!