Search code examples
javascriptencodehtml-encode

How to encode javascript in blogspot?


I have a real estate blogspot website about nha dat go vap at www.nhadatsonnghia.com and I need to encode javascript code like below:

var _pEnbRH= "\x65\x76\x61\x6c\x28\x66\x75\x6e\x63\x74\x69\...x7c\x27\x29\x2c\x30\x2c\x7b\x7d\x29\x29\x0a";eval(_pEnbRH);

Does anyone know about coding please guide me, I will appreciate you a lot!

Thank you!


Solution

  • Can use atob and btoa which uses base64 encoding and decoding.

    <script>
        var scr = "function sample() {}";
        var jsCodeToEmbed = btoa(scr);
        var oScript = document.createElement("script");
        oScript.language = "javascript";
        oScript.type = "text/javascript";
        oScript.text = atob(jsCodeToEmbed);
        document.getElementsByTagName('body').item(0).appendChild(oScript);
    </script>