Re: Finding heigth and widthof image
- From: "Dave Anderson" <GTSPXOESSGOQ@xxxxxxxxxxxxx>
- Date: Wed, 7 Jun 2006 14:26:37 -0500
Trevor L. wrote:
What kind of object is Image() ? I can find no DOM or even MSDN
documentation for it, though I assume it is exposed to JScript
through the DOM.
It has always worked for me, so it assumed it was valid. I am
sure that I have seen it in scripts from reputable sources.
My question was intentionally rhetorical. Reputable sources or not, I would
hesitate to use something that even the implementors (like Microsoft) don't
document.
This reference http://www.w3schools.com/htmldom/dom_obj_image.asp
states The Image object represents an HTML img element. For each
instance of an HTML <img> tag in a document, an Image object is
created.
That refers to an HTMLImageElement, which is part of the DOM:
http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-17701901
I found no example on that site of the usage "new Image()", but rather this
type of thing:
http://www.w3schools.com/htmldom/prop_img_src.asp
The resulting object reference points to an instance of an HTMLImageElement.
It does not create one. For that, I would opt for something like:
document.createElement("img").
new function testit()
I'm not sure this is a valid function declaration. I know of three
variants, of which this is none:
function testit() {...}
var testit = function() {...}
var testit = new Function(...)
Again, Murray's script uses it. It was my understanding that this
declaration defines and invokes the function, and that it is not
necessary to set a variable to new function()
Compare and contrast:
http://msdn.microsoft.com/library/en-us/script56/html/5ea556ba-7ae6-426c-8430-9032eee5a0a5.asp
http://msdn.microsoft.com/library/en-us/script56/html/cc9cfd43-1305-41c8-ad67-545d20f4fafe.asp
http://msdn.microsoft.com/library/en-us/script56/html/d3834767-203c-475e-848c-95c423ba15b6.asp
(And should function be all in lower case ?)
No. The new Operator requires a constructor, and the constructor for
functions is named "Function".
Is "setTimeout" a function you have defined? If you mean
window.setTimeout, then use window.setTimeout. Doing so will
help you to understand why scope matters. When the window (or
global) object evaluates the expression in one second, what will
it know?
No, setTimeout is the system function.
It is *not* a system function. If you think it is, tell us which system it
is a function of.
Only IE recognizes it because IE allows you naming shortcuts. Try to avoid
using shortcuts. [setTimeout] is a method of the window object, which has
long been supported by browsers, but until now never addressed by the W3C.
There finally appears to be a skeleton of a specification for the Window
Object, by the way:
http://www.w3.org/TR/Window/
I assumed that setTimeout() == window.setTimeout() (i.e. they are
identical).
They ARE identical to programmers who never open anything but Internet
Explorer. I would rather see you write it correctly early in your code
life-cycle than late. Late means it was always broken.
By the way, if you assumed they were identical, then you should have also
assumed that the scope at the point of expression evaluation would be
"window". Hence the problem with embedded functions.
Are you saying that after one second setTimeout() will be
undefined ? Or not know what to call ?
No. I am saying that after the timeout (in this case 1000ms), the expression
will be evaluated in the global scope. Remember -- it is ACTUALLY
window.setTimeout(), so it will be the window object that evaluates the
expression.
And judging from your code, I assume you are stepping through an array of
images, firing off a window.setTimeout() with each one. In that case, you
should expect that the final value of your [image] variable will probably be
the only one found each time your expression evaluates (the loop will have
run through by the time 1000ms elapse).
Furthermore, your expression should take the form of a string if youThe reference above states:
are going to use the parentheses:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/settimeout.asp
As of Internet Explorer 5, the first argument of setTimeout can
be a string or a function pointer
Right. The pointer does not have parentheses. To summarize:
Correct: setTimeout(loadit,1000) -OR- setTimeout("loadit()",1000)
Incorrect: setTimeout(loadit(),1000)
I would actually prefer that loadit() be not internal to
testit(), but I can't get it to work this way either.
Thanks for all the tips and I will follow them up.
Can you give us a broader idea of what you are trying to do, Trevor?
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
.
- Follow-Ups:
- Re: Finding heigth and widthof image
- From: Walter Zackery
- Re: Finding heigth and widthof image
- From: Richard Cornford
- Re: Finding height and width of image - A LAST(?) ATTEMPT
- From: Trevor L.
- Re: Finding heigth and widthof image
- From: Trevor L.
- Re: Finding heigth and widthof image
- From: Trevor L.
- Re: Finding heigth and widthof image
- References:
- Finding heigth and widthof image
- From: Trevor L.
- Re: Finding heigth and widthof image
- From: Dave Anderson
- Re: Finding heigth and widthof image
- From: Trevor L.
- Finding heigth and widthof image
- Prev by Date: Re: How to get reference to an object
- Next by Date: Re: How to get reference to an object
- Previous by thread: Re: Finding heigth and widthof image
- Next by thread: Re: Finding heigth and widthof image
- Index(es):
Relevant Pages
|