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


Groups > comp.lang.javascript > #31599 > unrolled thread

iframe function

Started byAndrew Poulos <ap_prog@hotmail.com>
First post2016-10-24 14:03 +1100
Last post2016-10-24 12:16 +0100
Articles 14 — 7 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#31599 — iframe function

FromAndrew Poulos <ap_prog@hotmail.com>
Date2016-10-24 14:03 +1100
Subjectiframe function
Message-ID<obqdnb-4PICQ55DFnZ2dnUU7-IHNnZ2d@westnet.com.au>
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.

Andrew Poulos

[toc] | [next] | [standalone]


#31600

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-10-24 04:26 +0100
Message-ID<1766631.oMNUckLgyt@PointedEars.de>
In reply to#31599
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?

Yes.

<http://catb.org/esr/faqs/smart-questions.html#prune>
<http://catb.org/esr/faqs/smart-questions.html#idm45835691719280>
 
> 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.

<http://catb.org/esr/faqs/smart-questions.html#idm45835691716720>

-- 
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.

[toc] | [prev] | [next] | [standalone]


#31602

FromAndrew Poulos <ap_prog@hotmail.com>
Date2016-10-24 19:17 +1100
Message-ID<4sSdnU3AsOIeXpDFnZ2dnUU7-TXNnZ2d@westnet.com.au>
In reply to#31600
On 24/10/2016 2:26 PM, Thomas 'PointedEars' Lahn wrote:
> 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?
>
> Yes.
>
> <http://catb.org/esr/faqs/smart-questions.html#prune>
> <http://catb.org/esr/faqs/smart-questions.html#idm45835691719280>
>
>> 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.
>
> <http://catb.org/esr/faqs/smart-questions.html#idm45835691716720>

Your understanding of JavaScript and other internet-based technologies 
is unquestioned (at least by me) but I often feel your advice is less 
than helpful.

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#31603

FromTim Streater <timstreater@greenbee.net>
Date2016-10-24 10:03 +0100
Message-ID<241020161003047932%timstreater@greenbee.net>
In reply to#31602
In article <4sSdnU3AsOIeXpDFnZ2dnUU7-TXNnZ2d@westnet.com.au>, Andrew
Poulos <ap_prog@hotmail.com> wrote:

>On 24/10/2016 2:26 PM, Thomas 'PointedEars' Lahn wrote:
>> 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?
>>
>> Yes.
>>
>> <http://catb.org/esr/faqs/smart-questions.html#prune>
>> <http://catb.org/esr/faqs/smart-questions.html#idm45835691719280>
>>
>>> 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.
>>
>> <http://catb.org/esr/faqs/smart-questions.html#idm45835691716720>
>
>Your understanding of JavaScript and other internet-based technologies 
>is unquestioned (at least by me) but I often feel your advice is less 
>than helpful.

I think you mean "never helpful".

-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#31604

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-10-24 11:16 +0100
Message-ID<4984144.DvuYhMxLoT@PointedEars.de>
In reply to#31602
Andrew Poulos wrote:

> Your understanding of JavaScript and other internet-based technologies
> is unquestioned (at least by me) but I often feel your advice is less
> than helpful.

As you can see from the references, the latter too often applies to your 
"questions".  Read, think, post; in that order.

-- 
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.

[toc] | [prev] | [next] | [standalone]


#31605

FromTim Streater <timstreater@greenbee.net>
Date2016-10-24 11:28 +0100
Message-ID<241020161128446348%timstreater@greenbee.net>
In reply to#31604
In article <4984144.DvuYhMxLoT@PointedEars.de>, Thomas 'PointedEars'
Lahn <PointedEars@web.de> wrote:

>Andrew Poulos wrote:
>
>> Your understanding of JavaScript and other internet-based technologies
>> is unquestioned (at least by me) but I often feel your advice is less
>> than helpful.
>
>As you can see from the references, the latter too often applies to your 
>"questions".  Read, think, post; in that order.

A proper teacher can guess the source of confusion in someone's mind by
reading the question and applying a bit of thought. You are evidently
incapable of doing this.

-- 
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee

[toc] | [prev] | [next] | [standalone]


#31608

FromLuuk <luuk@invalid.lan>
Date2016-10-24 19:19 +0200
Message-ID<580e42a6$0$872$e4fe514c@news.xs4all.nl>
In reply to#31604
On 24-10-16 12:16, Thomas 'PointedEars' Lahn wrote:
> Andrew Poulos wrote:
>
>> Your understanding of JavaScript and other internet-based technologies
>> is unquestioned (at least by me) but I often feel your advice is less
>> than helpful.
>
> As you can see from the references, the latter too often applies to your
> "questions".  Read, think, post; in that order.
>

The order should be:
Read, think, think again, type post, think again, post

This 3rd item it to make sure you REALLY understand what is being 
questioned.....

This fifth item is too often forgotten. It should help in getting 
ananswer to "Is this answer helpfull to the person asking the question?"

[toc] | [prev] | [next] | [standalone]


#31609

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-10-25 21:19 +0100
Message-ID<zeK1SxQL57DYFwV8@invalid.uk.co.demon.merlyn.invalid>
In reply to#31608
In comp.lang.javascript message <580e42a6$0$872$e4fe514c@news.xs4all.nl>
, Mon, 24 Oct 2016 19:19:36, Luuk <luuk@invalid.lan> posted:

>On 24-10-16 12:16, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>
>>> Your understanding of JavaScript and other internet-based technologies
>>> is unquestioned (at least by me) but I often feel your advice is less
>>> than helpful.
>>
>> As you can see from the references, the latter too often applies to your
>> "questions".  Read, think, post; in that order.
>>
>
>The order should be:
>Read, think, think again, type post, think again, post
>
>This 3rd item it to make sure you REALLY understand what is being
>questioned.....
>
>This fifth item is too often forgotten. It should help in getting
>ananswer to "Is this answer helpfull to the person asking the
>question?"


Good, but incomplete.

Before starting to write a follow-up, one should re-read the previous
article[s].  And re-read likewise after composing the answer.  Both of
those should be in "do until OK" loops.

Also, whenever reasonably feasible, any code in the answer should be
tested in another such loop.

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#31616

FromLuuk <luuk@invalid.lan>
Date2016-10-26 22:30 +0200
Message-ID<58111275$0$867$e4fe514c@news.xs4all.nl>
In reply to#31609
On 25-10-16 22:19, Dr J R Stockton wrote:
> In comp.lang.javascript message <580e42a6$0$872$e4fe514c@news.xs4all.nl>
> , Mon, 24 Oct 2016 19:19:36, Luuk <luuk@invalid.lan> posted:
>
>> On 24-10-16 12:16, Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>>>
>>>> Your understanding of JavaScript and other internet-based technologies
>>>> is unquestioned (at least by me) but I often feel your advice is less
>>>> than helpful.
>>>
>>> As you can see from the references, the latter too often applies to your
>>> "questions".  Read, think, post; in that order.
>>>
>>
>> The order should be:
>> Read, think, think again, type post, think again, post
>>
>> This 3rd item it to make sure you REALLY understand what is being
>> questioned.....
>>
>> This fifth item is too often forgotten. It should help in getting
>> ananswer to "Is this answer helpfull to the person asking the
>> question?"
>
>
> Good, but incomplete.
>
> Before starting to write a follow-up, one should re-read the previous
> article[s].  And re-read likewise after composing the answer.  Both of
> those should be in "do until OK" loops.
>

that migh give an infinite loop........

;)

> Also, whenever reasonably feasible, any code in the answer should be
> tested in another such loop.
>

Thanks for your response!

[toc] | [prev] | [next] | [standalone]


#31614

FromJoao Rodrigues <groups_jr-1@yahoo.com.br>
Date2016-10-26 06:15 -0200
Message-ID<nupont$19uj$1@gioia.aioe.org>
In reply to#31602
On 24-10-2016 06:17, Andrew Poulos wrote:
> On 24/10/2016 2:26 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:

>
> Your understanding of JavaScript and other internet-based technologies
> is unquestioned (at least by me) but I often feel your advice is less
> than helpful.
>
> Andrew Poulos

You finally saw the light.

-- 
Joao Rodrigues

[toc] | [prev] | [next] | [standalone]


#31622

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-10-27 22:11 +0100
Message-ID<1762026.oMNUckLgyt@PointedEars.de>
In reply to#31614
Joao Rodrigues wrote:

> On 24-10-2016 06:17, Andrew Poulos wrote:
>> On 24/10/2016 2:26 PM, Thomas 'PointedEars' Lahn wrote:
>>> Andrew Poulos wrote:
>> Your understanding of JavaScript and other internet-based technologies
>> is unquestioned (at least by me) but I often feel your advice is less
>> than helpful.
> 
> You finally saw the light.

No, that is yet to happen.  For you, too.

-- 
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.

[toc] | [prev] | [next] | [standalone]


#31601

FromJJ <jj4public@vfemail.net>
Date2016-10-24 13:25 +0700
Message-ID<16w23ipep3k6w$.1zxui9r36ciz$.dlg@40tude.net>
In reply to#31599
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.
> 
> Andrew Poulos

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.

Otherwise, the aVar checked by myFunc would be the one in the IFRAME's
document. The reason is that the myFunc() in the parent window is only a
reference to myFunc() in the IFRAME. The function itself is still in the
IFRAME. Thus, it only sees the aVar variable in the IFRAME.

[toc] | [prev] | [next] | [standalone]


#31606

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-10-24 11:58 +0100
Message-ID<5211838.lOV4Wx5bFT@PointedEars.de>
In reply to#31601
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.

[toc] | [prev] | [next] | [standalone]


#31607

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-10-24 12:16 +0100
Message-ID<4243030.31r3eYUQgx@PointedEars.de>
In reply to#31606
Thomas 'PointedEars' Lahn wrote:

> 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).

The proper key word is “lexical _environment”; see in particular 
<http://www.ecma-international.org/ecma-262/7.0/#sec-function-definitions-runtime-semantics-evaluation> (the 7th edition, of 2016, is easier to read 
at least because of better site navigation).

-- 
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web