"TheKeith" <no@spam.com> writes:
[color=blue]
> "Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
> news:7k2w49e5.fsf@hotpop.com...[color=green]
> > Remember to add a !DOCTYPE[/color][/color]
....[color=blue]
> I always do--I just left it out for clarification's sake.[/color]
Good :)
[color=blue][color=green]
> > You don't need HTML comments in your Javascript code.[/color]
>
> Really! I thought you were supposed to use it to hide the script from
> browsers that can't read it?[/color]
Correct.
Those browsers are not the ones that just don't support Javascript. It
is the ones that don't even understand the script *tag*. The latest
such Netscape was version 1, the latest IE was version 2. I haven't
seen any browser made after 1997 that didn't understand the script tag
well enough to not render the content.
There are some, dated, utilities that gets confuzed. I wouldn't worry
about that unless I use them myself, as the author of the page.
[color=blue]
> Is that just something that most programmers have abandoned since
> all newer browsers support js?[/color]
Too few programmers have abandoned it. The Crusade Against HTML
Comments in Javscript(TM) will fight this bad habit to the end! :)
It is time to move on.
It is also a bad idea in XHTML, since a conformant XML parser must
ignore everything inside comments *before* starting to interpret it
(IIRC).
[color=blue]
> I didn't know there was a difference between declaring your variables with
> the var in front and without. Could you explain the difference? Thanks.[/color]
Without the var in front, you don't *declare* the variable. Assigning
to an undeclared variable name will create a new global variable of
that name.
Inside a function, the "var" keyword is used to declare local variables.
If you have a global variable called "foo" and a function declares a local
variable of the same name, then inside the function body, only the local
variable is visible. Changes to it doesn't affect the global variable.
Example:
---
<script type="text/javascript">
var foo = 42; // *declares* variable in global scope
function bar() {
var foo = "arglebargle"; // declares variable as local in function's scope
foo += foo;
return foo;
}
alert(bar());
alert(foo);
</script>
---
This alerts first "arglebarglearglebargle" and then "42".
You can assign to global variables without declaring them first.
---
<script type="text/javascript">
var foo = 42;
bar = 37;
alert(foo + bar);
</script>
---
This alerts "79". Afterwards, both "foo" and "bar" are global variables
(i.e., properties of the global object).
You cannot *read* from undeclared global variables
---
<script type="text/javascript">
var foo;
alert(foo);
alert(bar);
</script>
---
This alerts "undefined" (the value given to a declared but
uninitialized variable), and then it gives an error because
"bar" is an undeclared variable.
There is no reason not to declare your global variables. In fact,
recently, someone had troubles because he was using undeclared global
variables with the same name as an element's id. I believe declaring
the variables solved the problem.
There is absolutely no reason not to declare your local variables.
Programming is much easier when you have local scopes. You don't have
to worry that your variable is named the same as some other function's
variable.
[color=blue]
> Got it--much appreciated. What should I put in the href section?[/color]
A link to a page that either:
1) substitutes for what you try to do, just without the javascript.
E.g., if you want to open a fancy window to show an image, then put
plain link to the image, so people without Javascript can still see
it. They just miss the extra bells and whistles.
or,
2) if that is not possible, put a link to a page that explains why
your page requires Javascript in order to function.
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'