Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need the power to lock out the "view code" option.

Status
Not open for further replies.

canix

Technical User
Jun 1, 2000
41
US
I am working on a page where the code is sacred. I need to at least lock the code down.. If anyone can help out, I would appreciate it.

Thanks Much
Canix
 
Would you like me to bless it for you? ;-)

There is no way to hide source code from browsers, that is what they use to render your page.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
you cannot lock out any of your code, but the closest thing is you can link to your javascripts:

<script language=javascript src=something.js></script>

just copy everything inside your script tags now, and put in a .js file (with notepad). then link as shown


theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
The SRC attribute is only available in Javascript1.1 and later, so be aware that you'll be locking out users that have *ancient* browsers by using it. It may be a little silly to try to write for these older browsers in most circumstances, but I'm sure there are clients out there that put that requirement in their specs.

As Tom and eclipse said, it is _absolutely_ impossible to prevent people from seeing your code. This question has been asked and answered numerous times in this forum. In my opinion, it's a waste of time and energy implementing naive techniques with this as their end, even when they're applied to *sacred* code ;-)

Russ
bobbitts@hotmail.com
 
There is a way, not perfect but pretty good. Put your code in a 1 pixel frame (You can try zero but some browsers don't like that), and everything else in a second frame. Include in the first frame the following function to run onLoad:
function
shut(){
if(parent.document.title == self.document.title) { document.location = &quot;parent.htm&quot;}

where parent.htm is the name of your parent frameset page. It will protect your code from most snoopers.
Carl
ps: You could probably also do away with the function and just keep the if statement, but I have not tested it, to accomplish the same thing.
 
Carl, that does not prevent anyone from viewing your source. It just obscures it a little. If someone really wanted it, they could get it trivially. For instance, they could see that you are using a frameset, copy the URL for your &quot;hidden&quot; frame, and paste it in their address bar. There is *NO* way to &quot;lock away&quot; your source.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
I'm having a hard time understanding what could be &quot;sacred&quot; about HTML or JavaScript code on one's page. The web is what it is due in large part to the practice of code &quot;borrowing.&quot; Kevin
slanek@ssd.fsi.com
 
if it was only borrowing, it would'nt evolve much ... i think it's more of a &quot;borrowing &amp; adapting&quot; story ;-)
 
tanderso wrote
&quot; For instance, they could see that you are using a frameset, copy the URL for your &quot;hidden&quot; frame, and paste it in their address bar. There is *NO* way to &quot;lock away&quot; your source.&quot;
Not true. The method I described above can be gotten around but not by simply doing this. I have used it with several 1000 students and only a few have gotten into the JavaScript.
Carl
 
so you (carl) and tom basically agree : there is no way to hide the code to every user, but there is some to hide it to most users
 
Yes Iza, borrowing AND adapting is a much better expression. The point is, there is no reason to hide your HTML or JS code. Nothing in the code could be that sacred. I'm open to criticism though. If you can think of a reason I'd like to hear it.

Another thought, even if you could hide your code, it wouldn't take a genius to reverse engineer your page and get the exact same result. It could be done fairly easily. Kevin
slanek@ssd.fsi.com
 
and what's more, an algorithm doesn't belong to you even if YOU created it (at least here !!! only the FORM/SHAPE is protected)
anyway i agree with kevin, i guess we all learnt a few tricks in reading someone else's code (html or javascript or whatever) and that's not such a deal to share what you've finally learnt- i mean it's giving back what you have been given !
 
(but i still wonder what a sacred code could be s-) )
 
You might want to hide the code if it contained answers to questions, for example. Of course, you might want do other things to disquise the answers also. If you want to see my example at work go to select any chapter and go to practice problems.
BTW I wrote a JavaScript password protection that only one person has been able to crack. View source won't do it! I am on the road so I don't have the URL handy but when I return I will post the URL if anyone is interested,
Carl
 
Very cool. So in a case like that, code-theft isn't really the issue. You're more concerned about students being able to cheat on the answers. Now that I can understand.

Great example BTW. Kevin
slanek@ssd.fsi.com
 
For that, you should use CGI and write your answers to a file. JavaScript simply is not meant for that purpose and can not do it well.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
I'm sorry, you lost me Tom. What is it that JS is not meant to do in Carl's example? Kevin
slanek@ssd.fsi.com
 
JavaScript is not meant to save any information in a way which disguises it from users. JavaScript is meant to manipulate HTML elements and events. If you want to have hidden information, save it on your server using CGI and access it at the correct time using CGI.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
yes, i agree, if you want something secure, you should use server side code, otherwise, you are just asking for people to cheat. adam@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top