Vamsi Pavan’s Place

When curiousity outbursts …..

Hiding Javascript Source

December 30th, 2006 · No Comments · Java Script

When you code an external javascript you identify that it is a javascript using either or both of the language and type parameters on the script tag. The file suffix of .js doesn’t get referenced in determining that the called module is javascript. This means thatr we don’t need to use the .js suffix on our javascript code and can use a different suffix that will allow us to make the javascript source much more difficult to obtain.

If we use a .htm suffix on our filename instead of .js then any attempts to access the file separately (as would be done by someone trying to access the source code) will result in the file being processed as if it is an html web page instead of as a javascript (at least by the Internet Explorer and Netscape web browsers). By cleverly including some html commands into the javascript source we can make access to the actual javascript source much more difficult.

So let’s see this in action. I have created a javascript to demonstrate this which I have called hide.htm. The javascript is linked into this page using the following code:
‘; tags and is therefore effectively commented out leaving only h = ‘ ‘; to display on the page. To view the commented out javascript code would require viewing the source of that page.

Many of your visitors will not be able to do this easily because to be able to view the source of that page first requires that the page be displayed in the browser. The script code contained in that first assignment statement will be interpreted as a javascript to be executed when the file is displayed as a web page and that script contains instructions to load and display a different page - the one that uses the actual script. The page will therefore not display long enough for your visitors to view the source unless they first disable javascript.

Note that this may not work with all browsers but does work with the latest versions of Internet Explorer, Netscape, and Opera.

Bookmark it! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Live
  • StumbleUpon
  • BlinkList
  • YahooMyWeb
  • NewsVine
  • blogtercimlap
  • Netvouz
  • Technorati
  • Slashdot
  • Print this article!

Tags:

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment