Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30289
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: A few problems with looping thru a set of elements with the same "name" specifier. |
| Date | 2016-04-17 15:30 +0200 |
| Organization | albasani.net |
| Message-ID | <nf035v$b42$1@news.albasani.net> (permalink) |
| References | <571371bd$0$5928$e4fe514c@news.xs4all.nl> |
R.Wieser wrote:
> #1: I've written a script to address an element with the attribute name
> "foo". The problem is that a certain, bit older browser fails on
> "document.foo.length" if there are less than 2 elements available. Is
> there a certain trick involved to have it return the values One and Zero too
> ?
>
> Related: With two-or-more elements I can address a single one by referring
> to it in an array-like fashion: "document.foo[i].getAttribute(...)". With
> only a single element being present using
> "document.foo[0].getAttribute(...)" fails, but works without the "[0]".
>
> #2: Can I give two different elements the same "name" propery and than
> address them individually, something like "document.div.foo.*" perhaps ?
>
> Related: How can I refer to embedded elements ("document.foo.h1.*" perhaps)
> ?
Use getElementsByName() or querySelector() / querySelectorAll(). Maybe these
will work on the "certain older browser", maybe not. Unfortunately, we don't
know what browser that is.
> #3: The script is supposed to executed every few seconds, so I added
>
> setTimeout("scriptName()", Timeout)
>
> as the last line of the script. The problem is that some browsers seem to
> block this, probably because of some kind of popup protection. Is there a
> method/function I should be using instead of that "setTimeout" that will not
> run into those troubles ?
>
> #4: If I call the script from the element itself and use "this" as an
> argument to the script (as a reference to the current object), how am I
> supposed to put that argument in the "setTimeout" call ? The below does
> not seem to work:
>
> setTimeout("scriptName("+ this +")",Timeout)
Your terminology is all over the place - I had to re-read all of your
questions several times before I figured out what you meant...
You cannot call scripts, only functions. I assume this means that you really
added the setTimeout() call as the last line of your _function_.
Why would a popup blocker prevent execution? Does your function open a new
window? If so, why would you call it every few seconds? Hard to say, without
knowing what the (oddly named) scriptName() function does. Also, which
browsers are "some browsers"?
"Calling the script from the element itself" could mean that you're using
event handler attributes in your HTML. How can you pass arguments to the
callback function, possibly also avoiding problems with `this`? It depends
on what that "certain older browser" is. For current browsers, you can just
add the arguments in the setTimeout() call; for IE9 and below you will have
to use a workaround. This is explained in detail here:
https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A few problems with looping thru a set of elements with the same "name" specifier. "R.Wieser" <address@not.available> - 2016-04-17 13:22 +0200
Re: A few problems with looping thru a set of elements with the same "name" specifier. Stefan Weiss <krewecherl@gmail.com> - 2016-04-17 15:30 +0200
Re: A few problems with looping thru a set of elements with the same"name" specifier. "R.Wieser" <address@not.available> - 2016-04-17 18:54 +0200
Re: A few problems with looping thru a set of elements with the same"name" specifier. Stefan Weiss <krewecherl@gmail.com> - 2016-04-18 19:46 +0200
Re: A few problems with looping thru a set of elements with thesame"name" specifier. "R.Wieser" <address@not.available> - 2016-04-18 20:28 +0200
Re: A few problems with looping thru a set of elements with thesame"name" specifier. Stefan Weiss <krewecherl@gmail.com> - 2016-04-18 22:54 +0200
Re: A few problems with looping thru a set of elements withthesame"name" specifier. "R.Wieser" <address@not.available> - 2016-04-19 11:24 +0200
Re: A few problems with looping thru a set of elements withthesame"name" specifier. Stefan Weiss <krewecherl@gmail.com> - 2016-04-19 15:42 +0200
Re: A few problems with looping thru a set of elements withthesame"name" specifier. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-19 20:08 +0200
Re: A few problems with looping thru a set of elements with the same "name" specifier. Stefan Weiss <krewecherl@gmail.com> - 2016-04-17 15:36 +0200
csiph-web