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


Groups > comp.lang.javascript > #25036

Re: Closing a lesson in iframe

Date 2014-06-26 14:26 +1000
From Andrew Poulos <ap_prog@hotmail.com>
Newsgroups comp.lang.javascript
Subject Re: Closing a lesson in iframe
References <sd2dnZqzLrIa-TbOnZ2dnUVZ_tednZ2d@westnet.com.au> <ReudnWKwTv88BDbOnZ2dnUVZ_tWdnZ2d@westnet.com.au>
Message-ID <icCdnQ9P9tQ5PDbOnZ2dnUVZ_sCdnZ2d@westnet.com.au> (permalink)

Show all headers | View raw


On 26/06/2014 1:52 PM, Andrew Poulos wrote:
> On 26/06/2014 10:06 AM, Andrew Poulos wrote:
>> I have a 3rd party elearning lesson displayed within an iframe. The
>> lesson contains a 'close' button which calls window.top.close(); - other
>> lessons might call window.close();
>>
>> The parent window contains the learning management system (LMS). This
>> window is not to close when the lesson is closed.
>>
>> I've tried a number of things and so far the closest I've got is this:
>>
>> // In the parent page the iframe is 'ifrm'
>> ifrm.onload = function() {
>>    var oDoc = (ifrm.contentWindow || ifrm.contentDocument);
>>    oDoc.top.close = fCloseFrame;
>>    oDoc.close = fCloseFrame;
>> };
>>
>> fCloseFrame = function() {
>>    var f= document.getElementById("cmtLesson");
>>    if (f) document.body.removeChild(f);
>> };
>>
>> It seems to "work" on my android phone but on my windows desktop and IE9
>> closes the parent window.
>>
>> If I add
>>    function foo() { window.alert('a'); }
>> to the lesson then from the parent page window.alert(oDoc.foo); IE will
>> correctly display foo.
>>
>> How can I intercept the call to close() from the iframe in the parent
>> with IE and only "close" the iframe itself?
>
> To answer my own question, I replaced the code above with
>
> function close() {
>    var tmp = document.getElementById("cmtLesson");
>    if (tmp) document.body.removeChild(tmp);
> }
>
> and IE, android... all seem to do what's needed.

Dang, it works if the lesson calls window.top.close() but not if it 
calls window.close();

Andrew Poulos

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


Thread

Closing a lesson in iframe Andrew Poulos <ap_prog@hotmail.com> - 2014-06-26 10:06 +1000
  Re: Closing a lesson in iframe Andrew Poulos <ap_prog@hotmail.com> - 2014-06-26 13:52 +1000
    Re: Closing a lesson in iframe Andrew Poulos <ap_prog@hotmail.com> - 2014-06-26 14:26 +1000
      Re: Closing a lesson in iframe Andrew Poulos <ap_prog@hotmail.com> - 2014-06-26 15:31 +1000
  Re: Closing a lesson in iframe Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-26 15:35 +0200
    Re: Closing a lesson in iframe Andrew Poulos <ap_prog@hotmail.com> - 2014-06-27 07:30 +1000
      Re: Closing a lesson in iframe Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-27 00:18 +0200

csiph-web