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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a javascript file from javascript

Status
Not open for further replies.

tav1035

MIS
Joined
May 10, 2001
Messages
344
Location
US
If I had a js file that I wanted to protect, couldn't I just write some javascript code that would reference my js file. Then I could scramble the 1st code so that references and the location could not be seen to the 2nd js file.

Here is what I have, but can't get it to work. It works when I have it embeded, but can't get the first code to work when I break them up.



1st code- embeded in the html, which I want to scramble
Code:
<script language="JavaScript"><!--
document.write('<script src="convertSpaces.js"><\/' + script>');
//--></script>



2nd code "convertSpaces.js" - is a js file sitting on the server
Code:
function convertSpaces(str)
{

str=str.replace(/\r/g,"")
str=str.replace(/\s/g,",")
str=str.replace(/\,,*/g,",")
str=str.replace(/\''*/g,"")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/(,*),$/,"$1")
str=str.replace(/\,,*/g,"','")
str=str.replace(/^','/g,"")

return str;
}




Code:
<textarea name="user" rows="10" cols="35" onBlur="this.value = convertSpaces(this.value);countWords(this.value);"></textarea>

The way it is supposed to work is->
when you type into the text box, it removes the spaces ect. when you click out.

Any help is appreciated,
Thanks
tav
 
No matter what you do to "protect" or scramble any content or script, it will, at some point, have to be unscrambled for the browser to understand it.

And - if it has to be unscrambled at some point, any user would be able to do the same unscrambling the browser has to, and thus see your code.

[!]Give up on this now.[/!]

See these 2 handy FAQs for more of the same advice:

"How do I hide my source code and protect my images": faq215-3101

"How do I keep my source code secret?": faq216-355

Perhaps you could tell us what is so special about your source that you don't wannt anyone to view it? Is it ground-breaking stuff? Does it do new things? Or do you simply want to stifle the ability to learn from your code?

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
BillyRayPreachersSon,
I actually don't care to hide it. I just don't want people to be able to download it and run it.
Here is a link to a small example of the online application.

It's a database application that will build SQL statements based off of known tables and fields. It while allow you to query the database then feeds the sorted results back into it to do updates. The user will not need to know SQL.

I have a subscription site set up to allow users to connect to there database and via this application.

I just wanted stop the subscribers from doing a file- save as- and using the application after their subscription runs out. I just wanted to hide the location of the js file that does the conversion.

tav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top