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


Groups > comp.lang.javascript > #31606

Re: iframe function

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder5.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: iframe function
Date Mon, 24 Oct 2016 11:58:31 +0100
Organization PointedEars Software (PES)
Lines 59
Message-ID <5211838.lOV4Wx5bFT@PointedEars.de> (permalink)
References <obqdnb-4PICQ55DFnZ2dnUU7-IHNnZ2d@westnet.com.au> <16w23ipep3k6w$.1zxui9r36ciz$.dlg@40tude.net>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1477306712 23205 eJwFwYEBwCAIA7CXgNlSz1GE/09Ygo/OykVwYTDsmx08bTuWGryqEEty79gxstPvhRUyYfgBGbIQrw== (24 Oct 2016 10:58:32 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Mon, 24 Oct 2016 10:58:32 +0000 (UTC)
User-Agent KNode/4.14.2
Cancel-Lock sha1:HW1oh2YOgWAmqSAyVtSc7Rqyj5w=
X-NNTP-Posting-Host eJwFwQkBwDAIA0BLfAnYaTviX8LukHS+LoIFQaaxQbaP7Y2gnwy4yF52rbJ0e1/kd2Rz8wcAXBCg
X-User-ID eJwFwYEBwDAEBMCVivxjHCT2H6F3MArHD8GDxd6rq70xVkGpV1qd3QLO984g77gvPcK0DJ4c6ykAVM+UH3jqFaI=
Xref csiph.com comp.lang.javascript:31606

Show key headers only | View raw


JJ wrote:

> On Mon, 24 Oct 2016 14:03:40 +1100, Andrew Poulos wrote:
>> If a page contains an IFRAME and the IFRAME has some JavaScript that
>> looks like:
>> 
>> var aVar = "hello";
>> 
>> var myFunc = function() {
>>    return (aVar == "hello");
>> };
>> 
>> window.parent.myFunc = myFunc;
>> 
>> and in the parent window I call myFunc() is the aVar value the one in
>> the IFRAME or the one in the parent window?
>> 
>> I've got a, for me, complex elearning course that uses an IFRAME for
>> some things and the parent window for others and I'm trying to debug
>> some errors but I don't really understand what the "correct" answer
>> should be.
> 
> First of all, if the IFRAME's document is in a different host, or using
> different protocol and/or port number, the code that assign a variable
> onto the parent window will fail due to cross scripting violation.

There are *several* possible reasons why after the assignment 
window.parent.myFunc !== myFunc; the Same Origin Policy, which you attempted 
to describe, is one of them.

> Otherwise, the aVar checked by myFunc would be the one in the IFRAME's
> document.

Incorrect.

> The reason is that the myFunc() in the parent window is only a
> reference to myFunc() in the IFRAME.

The *value* of window.parent.myFunc is a reference to an object _in heap 
memory_.

> The function itself is still in the IFRAME.

The function still is that object stored _in heap memory_.  “myFunc“ is a 
variable whose value is referring that object.

> Thus, it only sees the aVar variable in the IFRAME.

The function referred to by the value of “myFunc” compares against the value 
of the variable “aVar” declared in the iframe document because when the 
former was created it was *bound* to the latter (see: “closure” in general, 
and “lexical contexts” in the ECMAScript Language Specification, from the 
2015 Edition, in particular).

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
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

iframe function Andrew Poulos <ap_prog@hotmail.com> - 2016-10-24 14:03 +1100
  Re: iframe function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-24 04:26 +0100
    Re: iframe function Andrew Poulos <ap_prog@hotmail.com> - 2016-10-24 19:17 +1100
      Re: iframe function Tim Streater <timstreater@greenbee.net> - 2016-10-24 10:03 +0100
      Re: iframe function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-24 11:16 +0100
        Re: iframe function Tim Streater <timstreater@greenbee.net> - 2016-10-24 11:28 +0100
        Re: iframe function Luuk <luuk@invalid.lan> - 2016-10-24 19:19 +0200
          Re: iframe function Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-10-25 21:19 +0100
            Re: iframe function Luuk <luuk@invalid.lan> - 2016-10-26 22:30 +0200
      Re: iframe function Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-10-26 06:15 -0200
        Re: iframe function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-27 22:11 +0100
  Re: iframe function JJ <jj4public@vfemail.net> - 2016-10-24 13:25 +0700
    Re: iframe function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-24 11:58 +0100
      Re: iframe function Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-24 12:16 +0100

csiph-web