Wednesday, October 1, 2008

Hide javascript code?

How do you hide your underline javascript code from A HTML page..???
If you have any solution or any Idea please share ..?
NOTE:I know there are two way to get this thing, one is through SESSION which is written as Comment by an Anonymous user which is really appreciable, but this has some programming drawback. the Best I ever found is using Ajax. It is so dynamic that you can load javascript code according demand and loads in the memory directly hiding underline javascript code. If anyone want to to view this technology you are free to mail me.

1 comment:

Anonymous said...

On the page where the javascript is placed, add:

< ?
session_start();
if(!session_is_registered('allow_script'))
{
session_register('allow_script');
$allow_script = true;
}
? >
< html>
< head>
< script language="javascript" src="script.php">< /script>
< /head>
< body>
Body goes here...
< /body>
< /html>

And now create a new file called script.php and place your javascript there:

< ?
session_start();
if($allow_script)
{
header("Content-type: text/javascript");
? >

alert("Woohoo! My javascript Works!");

< ?
$allow_script = false;
}
? >

As you can see it uses a session. When you open the page where the javascript is placed it creates a session which allows the javascript to be viewed. But if you open script.php by its self, no session is created!

Try opening script.php in your browser window and you'll notice you can't view the code!