fredo wrote:
<snip>
// by "this.Heigh t", I mean the intrinsic height of the
image I'm trying to display
height:expressi on(eval(this.He ight <
(document.docum entElement.clie ntHeight!='unde fined' ?
document.docume ntElement.clien tHeight :
document.body.c lientHeight) ?
this.Height :
(document.docum entElement.clie ntHeight!='unde fined' ?
document.docume ntElement.clien tHeight :
document.body.c lientHeight)-50 ));
-----
But the image is always displayed using its intrinsic
height. What is wrong with the test in my code?
<snip>
It is difficult to see anything right with your code. First there is -
this.Height -, which evaluates as the - Height - property of the object
referred to by - this -.If - this - reefers to an IMG element's DOM
representation then it would not be expected to have a - Height -
property. The properties of IMG elements that have values corresponding
with the width and height attributes in the HTML mark-up (and may adopt
the dimensions values of the image in some browsers, including IE) are
called 'width' and 'height', with initial lowercase letters. The -
this.Height - reference is likely to evaluate as JScript's Undefined
value, and make a nonsense out of the 'less than' comparison (as it will
always result in what is effectively boolean false).
The call to the - eval - function surrounding the expression is
worthless (and like at least 99.9% of uses of - eval - in
JScritp/javascript code, indicative of an author who has no idea of what
they are doing). If the argument to the - eval - function is not of
string primitive type the - eval - function does nothing, returning its
argument unaltered. Here the argument to - eval - is going to be of
numeric primitive type, or of Undefined Type (though the nonsense that
has been made of the comparison should prevent that). The - eval - call
can be removed form the code with no other adjustments being needed,
making its presence in the code a sure sign that the author did not know
what the -eval - function does, or why it was included in the first
place.
The 'not equal' comparisons (both of them) are also a nonsense. The
comparison is between the value of -
document.docume ntElement.clien tHeight -, which will be numeric on IE
browsers, and the literal string primitive 'undefined'. This mix of
types in the operands is handled by having the operands type-converted
to numeric primitives prior to the comparison and a numeric comparison
performed to determine the boolean result. The string operand,
'undefined', would type-convert to the special numeric value NaN (Not a
Number) as it does not contain a character sequence that can be
interpreted as any number. The numeric NaN value is never equal to any
value, including itself, so the 'not equal' comparisons are always true.
Richard.