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


Groups > comp.lang.javascript > #19813

Re: Find an object in a window

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <31855897.f2HLQ4rEVA@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Sat, 18 May 2013 16:25:50 +0200
User-Agent KNode/4.10.2
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: Find an object in a window
Newsgroups comp.lang.javascript
References <G4WdnS1OUt3I-AnMnZ2dnUVZ_vadnZ2d@westnet.com.au> <2083966.lBPHQm9WGc@PointedEars.de> <p62dneXrfKXaUAnMnZ2dnUVZ_qCdnZ2d@westnet.com.au>
MIME-Version 1.0
Lines 85
NNTP-Posting-Date 18 May 2013 16:25:53 CEST
NNTP-Posting-Host f0b795b5.newsspool2.arcor-online.net
X-Trace DXC=bfTlbmFL11HWDmlTRbh@=IA9EHlD;3YcB4Fo<]lROoRA8kF<OcfhCOK=;L>dWjfmTBDZm8W4\YJNLb@mF9jNikdEBoKGPB=12AG\o_mJQWNmhM
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19813

Show key headers only | View raw


Andrew Poulos wrote:

> On 16/05/2013 7:12 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> I tried writing a recursive function (that sits in the elearning page)
>>> that searched all frames in the elearning's top window and in the top
>>> window of any opener which appears to work:
>>>
>>> function findAPI(win) {
>>>     if (win.API) {
>>>       return win.API;
>>>     }
>>>
>>>     for (var i = 0; i < win.frames.length; i++) {
>>         var api = findAPI(win.frames[i]);
>>         if (api) {
>>           return api;
>>>       }
>>>     }
>>>
>>>     if (win.opener && !win.opener.closed) {
>>>       return findAPI(win.opener.top);
>>>     }
>>> }
>>>
>>> function fLook() {
>>>     var foundApi = findAPI(window.top);
>>>     window.alert(foundApi);
>>> }
>>>
>>> Any ideas on how to make this (more) robust? For example, its not
>>> checking nested frames.
>>
>> Now it does.
> 
> Too easy! Thanks for the help.

You're welcome.  An omission and a further suggestion on my part, though.

The omission:

  for (var i = 0, len = win.frames.length; i < len; i++)

is more efficient than

  for (var i = 0; i < win.frames.length; i++)

and as safe if you can be sure that the number of items does not change 
while looping.  For that matter, if you stored the value of “win.frames” in 
a variable and access that variable instead, it would be even more 
efficient:

  for (var i = 0, frames = win.frames, len = frames.length;
       i < len; i++)
  {
    var api = findAPI(frames[i]);
    if (api) {
      return api;
    }
  }

Or you might want to wrap it as suggested e. g. in 
<http://naildrivin5.com/blog/2013/05/17/source-code-typography.html?utm_content=buffer5f552&utm_source=buffer&utm_medium=twitter&utm_campaign=Buffer> 
(from David Bryant Copeland [@davetron5000 at Github], by tweet of 
@kevinSuttle):

  for (var i = 0,
           frames = win.frames,
           len = frames.length;
       i < len; i++)
  {
    var api = findAPI(frames[i]);
    if (api) {
      return api;
    }
  }


The suggestion: _it's_ _e-learning_ :)

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

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


Thread

Find an object in a window Andrew Poulos <ap_prog@hotmail.com> - 2013-05-16 14:49 +1000
  Re: Find an object in a window Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-16 11:12 +0200
    Re: Find an object in a window Andrew Poulos <ap_prog@hotmail.com> - 2013-05-16 22:12 +1000
      Re: Find an object in a window Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-18 16:25 +0200
        Re: Find an object in a window Andrew Poulos <ap_prog@hotmail.com> - 2013-05-19 10:06 +1000

csiph-web