Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13213

Re: Finding the V offset of an element

From "Leonardo Azpurua" <leonardo@exmvps.org>
Newsgroups comp.lang.javascript
Subject Re: Finding the V offset of an element
Date 2012-04-04 10:28 -0430
Organization A noiseless patient Spider
Message-ID <jlhnhd$kmq$1@dont-email.me> (permalink)
References <jlgbcm$eti$1@dont-email.me> <jlgcp0$kss$1@dont-email.me> <tlgon71ol1nd21v94gcss1osimv21olv7k@4ax.com>

Show all headers | View raw


"Hans-Georg Michna" <hans-georgNoEmailPlease@michna.com> escribió en el 
mensaje news:tlgon71ol1nd21v94gcss1osimv21olv7k@4ax.com...
> On Tue, 3 Apr 2012 22:18:28 -0430, Leonardo Azpurua wrote:
>
>>    s.indexOf("TableRow") < 0 &&
>>    s.indexOf("Form") < 0) n += elt.offsetTop;
>
> Just a little remark on the sidelines: IE8 and older cannot do
> s.indexOf(...) .
>
> You may want to use something like this instead:
>
> function indexOf(s, a) {
> var index = -1;
> for (var i = 0; i < a.length; i++) {
> if (a[i] === s) {
> index = i;
> break;
> }
> }
> return index;
> }
>
> Hans-Georg

Hi, Hans Georg

Actually, I am not taking into account the existence of IE 8 or earlier.

Your code seems to be searching the first occurence of a character, not of a 
string, as String.indexOf does. It should go more along the lines of:

    function indexOf(where, pattern)
    {
        var index = -1;
        var pl = pattern.length;
        for (var i = 0; i <= where.length - pl; i++)
        {
            if (where.substr(i, pl) === pattern)
            {
                index = i;
                break;
            }
        }
        return index;
    }

My IE6 accepts <class>.prototype.<functionName> = <function>, and I 
regularly include an extensions.js file where I could inject the indexOf 
function in case it's not defined. But I am not worrying about older 
versions of IE, since these applications (if they ever get actually written) 
will be running in a rather controlled environment.

While veryfying the correctness of the above statements, I found out that, 
in my old IE6 the statement

document.write("indexOf('12345', '45') = " + '12345'.indexOf('45'));

Produces the correct output: indexOf('12345', '45') = 3.

I guess IE6 implementation of js depends on wscript, and I have it updated 
to the latest release for XP.


Thanks!

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 21:54 -0430
  Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:18 -0430
    Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:34 -0430
    Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-04 14:49 +0200
      Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-04 10:28 -0430
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:12 +0200
      Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-04 20:28 +0200
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:13 +0200
      Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 07:05 -0700
        Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-04 22:28 +0200
          Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 00:44 +0200
            Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 05:50 +0200
              Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 11:22 +0200
                Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 13:21 +0200
          Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-05 04:35 -0700
            Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 14:02 +0200
              Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-10 09:32 -0700
          Re: Finding the V offset of an element John G Harris <john@nospam.demon.co.uk> - 2012-04-05 14:54 +0100
            Re: Finding the V offset of an element Gene Wirchenko <genew@ocis.net> - 2012-04-05 08:37 -0700
  Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 04:57 -0700
    Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:16 +0200
      Re: Finding the V offset of an element "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-04-05 09:38 +0100
        Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-08 18:27 +0200
  Re: Finding the V offset of an element Dr J R Stockton <reply1214@merlyn.demon.co.uk.not.invalid> - 2012-04-06 21:52 +0100
    Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-07 11:18 -0430

csiph-web