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!

External JS Files

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I have several external JavaScript files that are loaded into each of my documents. They work fine on my PC with PWS and on another Web server with NT IIS but they don't work on an Apache Linux server. Is there something I can ask the ISP to add to the configuration? They are willing to help in any way they can. In reading various Web sites, I understand that this needs to be done on some Web servers and I can't find anything else wrong, nor was it clear what needed to be done. Any help or suggestions is appreciated! Thanks!

Don
 
Hi Gerald,

It's making me dizzy too! So weird!

As I said, the sample script I posted was a fully functional copy directly off my PWS on Windows NT workstation but the one online on the Apache server has a "real" URL. Anyway, I made a copy without the redirect line but it won't tell you anything because it still gives a Server500 HTML error page. The folks on the JavaScript forum say there is nothing wrong with the JS and all their suggestions, which were "variations on a theme," gave the same error. If you want to see the error for yourself, here is the URL:


Thanks!
Don [sig][/sig]
 
heh. ok well do one more thing. make another copy of secure.js in your cgi-bin and name it secure.txt and copy that file into the same directory as your index file as well.

if it gives a 500 error page when typed directly in the browser with a txt extension there is something really messed up in their apache server and possibly the only way they can fix that is to recompile apache with the latest version and reconfigure.

it is possible that they did something completely bizarre in their configuration file, but theres really no way to track that down unless you get a copy of their httpd.conf file.

try adding HTML tags to your .js files. put in <HTML> <HEAD></HEAD><BODY> at the beginning and </BODY></HTML> at the end.

maybe they are somehow checking every individual file for proper tags or something. adding html tags will make it unusable in the context that you want, it will tell us whether it is being checked for tags or not.

regards,
Gerald
[sig][/sig]
 
Hi Gerald,

That was a good idea, though it tells me what I knew - that if the JavaScript is embedded into the HTML directly, it works! At least this is a confirmation. First I created the text file with HTML headers per your suggestion. When loaded into the browser, it just shows the JavaScript code itself as expected:

Then, I added the Javascript header and footer tags and renamed it as an html file:

If you load it you'll get a blank screen but if you right-click, you probably won't get a popup, which is just the way it is supposed to work!

Now I still need to figure out what to do about it, short of going through the hundreds of files and pasting in the actual code!

Thanks!
Don [sig][/sig]
 
Ok we're getting somewhere now.
Take out the HTML tags in the secure2.txt file

just leave in the javascript code.

but leave it named secure2.txt

Gerald
[sig][/sig]
 
Hi Gerald,

OK, I removed the HTML tags from secure2.txt but also left off the JavaScript opening and closing tags (they weren't there anyway on this version of the file):

Also, I made a copy without any HTML but WITH the JavaScript opening and closing tags:

It works the same as before when one was a text file and the other was HTML: the first presents the code as text; the other runs the code.

Don [sig][/sig]
 
Gerald,

I followed the next logical progression and created a simple HTML file that loads secure2.txt into it - and it works! This is exactly what I did before so I don't know why it works now when it doesn't when loaded in the same directory as the HTML files. Those directories is no different than the one where index.html is located. Bother were created by me since this is a sub-site on the main account! Doesn't make sense!

Don [sig][/sig]
 
Are you sure that you refreshed your browser when you created the file in the same directory?

Yeah I just checked it out and it does work. Without the javascript tages. With the javascript tags it wont work.

So the server is definitely setup to parse .js files on the server side.

That means that there has got to be something in the httpd.conf file that references the .js extensions. Its really the only possibility unless they modified the apache source code.

In their configuration file, I bet there is something like this:

AddHandler cgi-script .cgi .pl .py .js
or
AddHandler cgi-wrap .cgi .pl .py .js
or
AddHandler server-parse .shtml .js

it is probably one of the first two

Have you asked the hosting company about that yet?

Do you have shell access?
You can probably find out yourself... Alot of times the httpd.conf file is world-readable.

Try opening it in vi.
There are 2 common locations of httpd.conf files, one is /etc/httpd/conf/httpd.conf and the other is /usr/local/apache/conf/httpd.conf

Then do a search for .js
To do a search in vi, hit the / key and type what you want to search for and enter.

If you see anything in there like what I showed you, tell your ISP that they must remove it and restart apache.

Otherwise, if you can live with modifying your files to call secure.txt instead of secure.js, everything should work fine if you rename secure.js to secure.txt and make sure there are no HTML or <SCRIPT> tags in it.


Regards,
Gerald
[sig][/sig]
 
Hi Gerald,

I just took the same test file the URL for which I apparently forgot to post a while ago and renamed the file with a .js extension again - and it seems to work! But I'm at home now and don't have the JavaScript debugging tools that I have at the office. Still, there is no &quot;error on page&quot; in the status bar and the script does seem to be producing the desired results. I viewed the source code just to be sure it was seeing secure2.js as the script.


But this does not work in my html or cgi-bin subdirectories. Could it be something as simple as folder or file permissions? I think they are set correctly but now I am beginning to wonder. I don't know what else would make it work in one directory but not in another.


Are you sure that you refreshed your browser when you created the file in the same directory?

Yes and in fact, I cleared all the cache and even went into the cache directory to be sure it was empty. I always view the source code just to be sure that it is seeing the proper file once I changed the name. It was.

Yeah I just checked it out and it does work. Without the javascript tages. With the javascript tags it wont work.

So the server is definitely setup to parse .js files on the server side.

That means that there has got to be something in the httpd.conf file that references the .js extensions. Its really the only possibility unless they modified the apache source code.

In their configuration file, I bet there is something like this:

AddHandler cgi-script .cgi .pl .py .js
or
AddHandler cgi-wrap .cgi .pl .py .js
or
AddHandler server-parse .shtml .js


it is probably one of the first two

Have you asked the hosting company about that yet?

Yes, and I have been sending them posts that contain things for them to try. The AddHandler was one of the first things we looked at, but it doesn't mean that all these different ones were tried.

Do you have shell access?
You can probably find out yourself... A lot of times the httpd.conf file is world-readable.


Try opening it in vi.
There are 2 common locations of httpd.conf files, one


is /etc/httpd/conf/httpd.conf and the other is /usr/local/apache/conf/httpd.conf

I do have shell access and was able to get to the root directory, but I could not find the file, dor did I find any recognizable sub directories. I'm still looking though.

Then do a search for .js
To do a search in vi, hit the / key and type what you want to search for and enter.


Is there anything wrong with Pico? That's what I'm used to using and it searches too.

If you see anything in there like what I showed you, tell your ISP that they must remove it and restart apache.

If I can't find the configuration file, I'll have them take a look themselves. They have been very flexible and co-operative so far

Otherwise, if you can live with modifying your files to call secure.txt instead of secure.js, everything should work fine if you rename secure.js to secure.txt and make sure there are no HTML or <SCRIPT> tags in it.

Well, I CAN but I would prefer not to! There are, quite literally, hundreds of files! In fact, I would like to have the ISP fix the problem on the configuration per these discussions if it's at all possible and leave the site alone.

Thanks a bundle to everyone!
Don
[sig][/sig]
 
Well. There is that too. Are you able to read any files fro the cgi-bin?

Check the cgi-bin for a .htaccess file. If there is a bad .htaccess/.htpasswd setup in that directory it could cause internal server errors.

To find the httpd.conf file, cd to the root directory and type the command:
find -name httpd.conf | grep httpd.conf

the grep pipe will weed out all of the permission denied errors from subdirectories that you dont have access to.

there is nothing wrong with pico. whatever editor you are comfortable with is fine.

but if you renamed it to .js and it is running from the document root then it is probably not in the conf file.

cd to your cgi-bin directory and type in:

ls -al

that will give you a list of all files, including hidden files. if you see a .htaccess file in there, delete it or rename it to something else and then try again.

if that does not work, do an ls -al in your main directory and see if you have a .htaccess file there. if you do, cut and paste it here.

or if you are not using frontpage extensions, you can probably delete it or rename it as well.

are you able to read a regular html file from your cgi-bin directory at all?


Regards,
Gerald

[sig][/sig]
 
Hi Gerald,

I'll take a look to see if I can find the httpd.conf file - - - no, just a million &quot;Permission Denied&quot; lines. If it found anything, it went by too fast to see.

But I think you are right that it is something in or about the cgi-bin directory. Although I do use .htaccess files here and there, there is not one in the cgi-bin. There is one in the directory where the test was done, but the one in the main directory should work for any directories under it that are not controlled by their own, shouldn't they? I tried putting it in the cgi-bin anyway but it made no difference as far as I can tell.

In fact, I realized just a few minutes ago that there are a couple other external JavaScript files there and they are working! It appears to be THIS JavaScript file that doesn't like to be there! So then I thought maybe it was the ../ in the path that it didn't like but that's not it either. What I finally did was to put the JavaScript file into my style directory which only contains a very simple style sheet. It seems to work fine from there.

The cgi-bin does have tons of Perl scripts and all work just fine so I don't think there could be a permissions problem with it. I doubt the Perl would work if that were the case.

Thanks again!
Don [sig][/sig]
 
Apparently I was mistaken that some JavaScript files were working in my cgi-bin. Closer study showed that they actually were not but after moving them to the directory where the style sheets are stored, they work fine. It is a subdirectory of the html folder but they do not seem to run in the html folder itself!

Also, I removed all or most of the test files so most of the links above no longer work.

Thanks to everyone for your help

Don [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top