Menu Close

Hide your Javascript in view-source


You may ask yourselves why someone need to hide some script? First – if this is something of your own and you do not want to be stolen, or to hide something from bots for example.

In my case, it all started with hiding my e-mail from bost to prevent spam in my inbox and then evolved to hiding the complete js code. Obfuscating your code is a good solution, but it’s not enough, because, although it is hard, someone could decipher your code.

What I’m actually doing is to delete the contents of my dom script element, so that after the browser evaluates your code, the code disappears.

For example, if your code is this:

<script type="text/javascript">
    //your code goes here

you just have to change it to this:

<script id="erasable" type="text/javascript">
    //your code goes here
    document.getElementById('erasable').innerHTML = "";

This is a simple hack. In any way, it cannot fully protect your code but it will make it quite a challenge.

Posted in Tips & Tricks

Related Posts

Leave a Reply

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

In order to use this website we use the following technically required cookies
  • bth_test_cookie
  • bth_logged_in_
  • bth_sec
  • bth_test_cookie
  • wp-settings-1
  • wp-settings-time-1

Decline all Services
Accept all Services