Re: Finding heigth and widthof image

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 you
are going to use the parentheses:

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/settimeout.asp

The reference above states:
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.


.



Relevant Pages

  • Re: Reading screen width and height
    ... It's a property of the window object, ... I doubt it's of much value for the IE DOM. ... I have MSDN CDs, ... > for properties of parentWindow. ...
    (microsoft.public.scripting.vbscript)
  • Re: addEvent - The late entry :)
    ... window object has an - EventTarget - method then all Nodes/Elements ... Opera 7, for example, had an - attachEvent - ... all of its nodes had - addEventListener - methods. ... Event handing on objects outside of the DOM needs to be handled completely independently of event handling on elements within the DOM. ...
    (comp.lang.javascript)
  • Re: REALbasic 2007 Release 2 Released
    ... I suspect is what that control uses in Windows also exposes the DOM)) ... Arbitrary window types likeWebkits black DOM inspector rampantly ... framework is based mostly on Cocoa. ...
    (comp.lang.basic.realbasic)
  • Re: When to use "document" and when to use "this"
    ... "window" is the default and top element of the DOM tree. ... as general scope of variables, where in a browser "window" is used. ... var v = 'Hello'; ...
    (comp.lang.javascript)
  • Can I capture a scene from a playing DVD
    ... I have screen capture software that gets a HDC for the desktop or window and ... copies it to a Image object. ... If the screen contains a window that is displaying a DVD movie that portion ...
    (microsoft.public.win32.programmer.directx.video)