View Full Version : Possible to restrict *.js access?

02-27-2003, 08:20 AM

This is a long shot, but is it possible to somehow restrict browser access to external Javascript file if someone specifically types in the *.js file URL?

What I had in mind was:

If *.js file URL typed into web browser
Display "Alternate" source code
Browser retrieves "real" Javascript

Obviously this an attempt to hide the Javascript source. Not foolproof, but partially effective?


02-27-2003, 08:38 AM
This is futile and has been discussed here many many times.:rolleyes:
read this article:

02-27-2003, 08:41 AM
I may be wrong, but anyway:


If *.js file URL typed into web browser

did you want to say:

if (window.location == "your.*js_file") ?

This won't work. The first think the browser does after pressing "Enter" is to redirect to the new URL. It does'nt run any script in the page anymore.

And how can you be sure, anyway, that somebody wo'nt use a _blank page as the starting point for typing in your *.js file's URL?

The only issue I see for your problem will be some script running on the server - that means anything but JS, and that script will block people to download your *.js files.

It may be PHP, but NOT JS.