Forum Moderators: open
Is there some sort of free software that will help me find errors?
Or...Ahem...Do any of you want to try to be my hero? :)
The link is in my profile.
it looks like you are missing about 50 semicolons
Well, since javascript implies a semicolon at the end of a line, this is not really the problem (although you are right, it would be good practice to terminate her statements with semicolons).
Still, the problem here is that she is not unescaping her quotes in her descriptions.
Anywhere you have something like:
desc = "And she said to me "woo hoo!" and jumped up and down" you need to have it like:
desc = "And she said to me \"woo hoo!\" and jumped up and down" Actually, this is a very verbose and repetitive script, and I can't help but think it could be done in a more elegant fashion. Maybe I could get a little time ...
I must be half asleep, I missed that
Anyway, I had some time on my hands so I modified both the script and the html files.
The new function that replaces all of the repetitive newwin1, newwin2, etc. functions is:
function newwin(obj,width,height,captionHeight) {
// grabs the href from the link
fileName = obj.href;
// grabs the title from the link
desc = obj.title;
// define array
pic = new Array(fileName,width,height,captionHeight);
} and it is called from the HTML by:
<a href="imageurl" onclick="newwin(this,380,380,0);
popupwin(); return false;" title="imagedescription">
<img src="thumbnailurl" hspace="6"></a> Note that I am defining the url and the description inline on the link itself, and then calling values in the function. This has the added benefit of allowing visitors to see the image if they have javascript turned off, since the link will then be followed to the image in the main window. Using the title for the caption is icing on the cake (it will also show up on a thumbnail image as a tooltip).
Even so, I'm sure there is probably an even more elegant solution. But now I am out of time.
Lauren, check your StickyMail for the full files.
Oh, one other thing. You still have to escape your quotes in the title attribute, but there you do it the HTML way -- with the " entity.
Nice little rewrite moonbiter.
Thanks too, tedster, for the tip on the Mozilla's javascript console. I didn't know that.
Now if I could only figure out Venkmann (the Mozilla debugger). ...
desc="And she said to me "
and thinks: "Hmm, no operators, so that must be the end of the statement. Now, where's the newline? Or the semicolon? Darn, it's missing!"
For relatively simple scripts, Netscape 4 is also useful. If the script doesn't run correctly, or at all, type javascript: into the address field. This will open a JavaScript console and show any JavaScript errors it has encountered during the current session.
About semicolons: No, in JavaScript, it is not bad practice to leave them out. JavaScript was specifically designed for an environment where potentially every single byte may count, so JavaScript statements are terminated either by a semicolon or a newline.
This is different from Java or C, which are compiled languages, and where the source code is designed to be human-readable (more or less). So comments in Java (for example) make no difference to the size of the compiled file, and Java source code is expected to be well-commented for ease of maintenance. In JavaScript, comments merely add bloat, so should be removed before releasing the script.
For long JavaScripts, I actually recommend removing not just comments, but unnecessary whitespace and, yes, semicolons. I've found you can make the file anything up to 50% smaller. I think of it as analogous to compiling a Java application: it's more important for it to be machine-readable than human-readable. I keep a human-readable version on file. (Although, if I find my scripts getting that long, I might decide to switch to a client-side script instead.)