views:

1048

answers:

4

I am using HTML, and I'd like to hide the SCRIPT tag from the user's view.

When the user views the page source, the definitions should not appear. How do I accomplish this?

Example

   <script type="text/javascript" src="My1.js"></script>
   <script type="text/javascript" src="My2.js"></script>
   <script type="text/javascript" src="jquery.js"></script>

I'd like to hide the definitions, any idea?

+12  A: 

You cannot hide HTML. If you want a closed source solution use a proprietary format such as Flash or Flex.

You can however obfuscate your javascript (you should shrinkwrap/minify it anyhow) which makes reading it harder.

apphacker
any code that executes client-side is by definition accessible to the computer which executes it - it's like asking how to make a raspberry with flammable juice. It simply cannot be done. (disclaimer: I am not a genetic biologist, but I feel pretty good about that statement.)
matt lohkamp
Flash and Flex are compiled into .swf files. That makes it a lot less accessible.
apphacker
It is as hard as hiding html code!
Trufa
+3  A: 

You can limit it to one script tag by making an include file that references the other scripts..

Other than that, no.

Ian P
A: 

It reads to me like he's wanting to completely eliminate it, not obfuscate it.

With that said, option #2 is to not use includes, and put obfuscated javascript in his HTML.

Ian P
A: 

You could also write script directly into the DOM. This also does not eliminate it (and the script to write the script would be there), but the user would have to use a DOM inspector (e.g. Firebug) to see it; it wouldn't be visible via 'view source'.

As others have said, this is just obfuscation, and simply kicks the problem down the road.

Hollister