PDA

View Full Version : Javascript question



Roarkiller
13th June 2007, 11:17 AM
I decided to give up trying to hunt down the perfect javascript menu and make one myself.

Thing is, there's this part about loading a .js file directly onto the page instead of writing it straight on the page that I don't get. Supposedly, you're supposed to write "<script src="linky.js"></script>" is wherever you want the script to be, then create a separate file "linky.js", and whatever is in that .js file should appear wherever you intended it to be.

Tested it on the page directly, works fine.

Tried the loading separately technique, got zilch.

So like, anyone can tell me what I'm doing wrong?

Jeff
13th June 2007, 12:12 PM
I'd make sure the <script> tag is inside the head tags, and add type="text/javascript" to the script tag, and see if it works.

Negrek
13th June 2007, 12:26 PM
Well, you have the correct code there, so I'd guess that there's just some silly little mistake somewhere that is screwing things up.

First, make sure that you didn't put those script tags into the "head" area of the document by accident (unless the JavaScript is supposed to be placed there and not in the body of the document).

Second, make sure that you spelled everything right, remembered to close your quotation marks on the link name, and stuff like that (I always screw that up, myself).

Make sure that there are no <script> tags within the external file itself.

If you're using relative linking like that (i.e. "filename.js" instead of "http://.....js"), make sure that you have everything in the same directory. Also make absolutely sure that you saved the script as a .js and not something else.

Yeah. It should work the way you've done it, so if none of those things seems to be the problem, perhaps post the source and I can look and see if I can figure out what's wrong with it; with what you've said, though, I couldn't think of anything else that might be a problem.

Roarkiller
13th June 2007, 09:16 PM
It's in the body, not the head.

<script src="linky.js"></script>

Here's what's inside the js file.

document.write("testing")

Simple basic write line. Still zilch. FYI for those wanting to know, I'm trying to do away with including a standard HTML menu on the side in every page, so I don't have to edit every page should I wnt to change the menu, so I figured javascript would be the safest bet (I'm not using frames, or iframes for that matter).

Jeff
14th June 2007, 12:27 AM
That's weird, it should be working, I tried it myself several different ways, in the head, in the body, with and without the type attribute defined. It worked every time (yeah even when placed in the head even though document.write code is supposed to go in the body).

What browser(s) are you testing this under?

Roarkiller
14th June 2007, 01:49 AM
Tried rewriting a test page, is working now. Still, I can't get a link out.

<a href="javascript:Start('index.html')";>index</a>
<a href="index.html">index</a>

That's what I changed, testing both a js link and a standard html link. Nothing came out.

Chris
14th June 2007, 07:51 AM
Make sure your server is reporting the MIME type of the external Javascript file as "text/javascript" otherwise some browsers (Firefox springs to mind) will refuse to execute the code.

Negrek
14th June 2007, 08:45 PM
FYI for those wanting to know, I'm trying to do away with including a standard HTML menu on the side in every page, so I don't have to edit every page should I wnt to change the menu, so I figured javascript would be the safest bet (I'm not using frames, or iframes for that matter).
If that's what you're doing with it, IMO you should use SSI instead. Very simple to use, obviously doesn't have problems with people who disable JavaScript or whatever, and it's designed especially to do stuff like include navigation bars where you only want to modify one file to have the changes appear on every page in a web site. Also doesn't suffer the same problems as frames/iframes. JavaScript isn't really designed to insert content like that.

Chris
15th June 2007, 05:48 AM
If that's what you're doing with it, IMO you should use shtml instead. Very simple to use, obviously doesn't have problems with people who disable JavaScript or whatever, and it's designed especially to do stuff like include navigation bars where you only want to modify one file to have the changes appear on every page in a web site. Also doesn't suffer the same problems as frames/iframes. JavaScript isn't really designed to insert content like that.

This is a pretty good solution and you should use this if your web server supports it. Most shared hosts still do.

Roarkiller
16th June 2007, 12:44 AM
Geocities doesn't. Hence javascript.

If you're wondering, SSI was what I have been using for all my non geocities-based webpages.


Make sure your server is reporting the MIME type of the external Javascript file as "text/javascript" otherwise some browsers (Firefox springs to mind) will refuse to execute the code.

Not very sure what you're talking about here. And uh, firefoz ain't gonna support this? Huh?

Btw, regarding my last post, that looks right, doesn't it?

Negrek
16th June 2007, 12:54 AM
IMO you should seek better free hosting than Geocities, but eh.

Firefox will support external JavaScript, but you have to make sure that the file is being correctly reported as a text/JavaScript file. If it's not, then you could try adding

<link href="whatever.js" type="text/javascript">

to the <head> of the page; I have no idea if that would clear the problem up or not, but I suppose it's worth a shot.