addEventListener on an window in an iframe

289 views
Skip to first unread message

Christophe Charron

unread,
Aug 13, 2007, 3:52:52 AM8/13/07
to
Hi,
because a context menu on a texbox, in a remote application, always
throws an exception, i'd like to disable it. No problem with a simple
window, I just have to do
window._content.addEventListener('contextmenu',function) (see here
http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_19_test01.xul)
But impossible to manage it when a window contains an iframe that
contains a window itself. It works (??) the first time but a soon as i
load an other window in the frame, it doesn't work anymore.
Is it possible to do it?
Am I doing something wrong ?

Here is my very simple window
http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_10_test01_en.xul

Best regards
Christophe Charron

Question

unread,
Aug 13, 2007, 4:30:49 AM8/13/07
to Christophe Charron, dev-te...@lists.mozilla.org
I think you can treat iframe as a new window.
If you set the src for the iframe. It's nearly the same with your opening an
window. So, there is another 'document' in the new 'window' object.

> _______________________________________________
> dev-tech-xul mailing list
> dev-te...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-xul
>

--
>: ~

Christophe Charron

unread,
Aug 13, 2007, 5:32:18 AM8/13/07
to
On 13 août, 10:30, Question <wanli...@gmail.com> wrote:
> I think you can treat iframe as a new window.
> If you set the src for the iframe. It's nearly the same with your opening an
> window. So, there is another 'document' in the new 'window' object.
>

ok but then what event must I listen and on wich objet must I do
listen ? I tried on the window_content of the window contained in the
iframe but it doesn't seem to work.


> On 8/13/07, Christophe Charron <christophe.charron....@gmail.com> wrote:
>
>
>
>
>
> > Hi,
> > because a context menu on a texbox, in a remote application, always
> > throws an exception, i'd like to disable it. No problem with a simple
> > window, I just have to do
> > window._content.addEventListener('contextmenu',function) (see here
>

> >http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_19...


> > )
> > But impossible to manage it when a window contains an iframe that
> > contains a window itself. It works (??) the first time but a soon as i
> > load an other window in the frame, it doesn't work anymore.
> > Is it possible to do it?
> > Am I doing something wrong ?
>
> > Here is my very simple window
>

> >http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_10...


>
> > Best regards
> > Christophe Charron
>
> > _______________________________________________
> > dev-tech-xul mailing list

> > dev-tech-...@lists.mozilla.org
> >https://lists.mozilla.org/listinfo/dev-tech-xul
>
> --
>
> >: ~


Neil

unread,
Aug 13, 2007, 5:51:42 AM8/13/07
to
Christophe Charron wrote:

>because a context menu on a texbox, in a remote application, always throws an exception, i'd like to disable it. No problem with a simple window, I just have to do window._content.addEventListener('contextmenu',function) (see here http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_19_test01.xul)
>But impossible to manage it when a window contains an iframe that contains a window itself. It works (??) the first time but a soon as i load an other window in the frame, it doesn't work anymore.
>
>

There are two issues here.
The first is that an event listener added to a frame only listens to
events in that frame, not in subframes.
The second is that when you load a document into a frame all of its
event listeners are removed.
As you seem to be writing an extension the solution is to add your event
listener to the tabbrowser rather than the content window. The
tabbrowser is special in that it can listen to all events in all frames
in all tabs.

--
Warning: May contain traces of nuts.

Christophe Charron

unread,
Aug 14, 2007, 3:24:33 AM8/14/07
to
On 13 août, 11:51, Neil <n...@parkwaycc.co.uk> wrote:
> Christophe Charron wrote:
> >because a context menu on a texbox, in a remote application, always throws an exception, i'd like to disable it. No problem with a simple window, I just have to do window._content.addEventListener('contextmenu',function) (see herehttp://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_19...)

> >But impossible to manage it when a window contains an iframe that contains a window itself. It works (??) the first time but a soon as i load an other window in the frame, it doesn't work anymore.
>
> There are two issues here.
> The first is that an event listener added to a frame only listens to
> events in that frame, not in subframes.
In fact, I understand this. That's why my event is on the window,
loaded into the frame and not on the frame itself. On the frame i do
"onload="event.stopPropagation();""

> The second is that when you load a document into a frame all of its
> event listeners are removed.
Ok I didn't know that

> As you seem to be writing an extension the solution is to add your event
> listener to the tabbrowser rather than the content window. The
> tabbrowser is special in that it can listen to all events in all frames
> in all tabs.
No, i'm not writing an extension but a remote app.

All codes can be seen here :
http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_10_test01_en.xul

Neil

unread,
Aug 14, 2007, 4:31:23 AM8/14/07
to
Christophe Charron wrote:

>On the frame i do "onload="event.stopPropagation();""
>
>

Load events aren't supposed to bubble, although old versions may still
have that bug.

>No, i'm not writing an extension but a remote app.
>
>

You confused me because window._content makes no sense for a remote app
(it's the same as window.top).

In this case, you have to add load event listeners to all your frames so
that when a document loads you can add all your other event listeners to
their windows. (Of course this doesn't really help in the case of
subframes...)

Christophe Charron

unread,
Aug 14, 2007, 4:58:32 AM8/14/07
to
On 14 août, 10:31, Neil <n...@parkwaycc.co.uk> wrote:
> Christophe Charron wrote:
> >On the frame i do "onload="event.stopPropagation();""
>
> Load events aren't supposed to bubble, although old versions may still
> have that bug.

What's an old version ? I'm using 2.0.0.6 !!!

>
> >No, i'm not writing an extension but a remote app.
>
> You confused me because window._content makes no sense for a remote app
> (it's the same as window.top).
>
> In this case, you have to add load event listeners to all your frames so
> that when a document loads you can add all your other event listeners to
> their windows. (Of course this doesn't really help in the case of
> subframes...)
>

I tried, here
http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_13_test01_en.xul
but it doesn't seem to work !

Neil

unread,
Aug 14, 2007, 7:52:55 AM8/14/07
to
Christophe Charron wrote:

>On 14 août, 10:31, Neil <n...@parkwaycc.co.uk> wrote:
>
>
>>In this case, you have to add load event listeners to all your frames so that when a document loads you can add all your other event listeners to their windows.
>>

You didn't add the other event listeners to the window, you added it to
the frame element (which doesn't work). Try fa_aay(window.toto); instead.

Christophe Charron

unread,
Aug 14, 2007, 10:28:22 AM8/14/07
to
On 14 août, 13:52, Neil <n...@parkwaycc.co.uk> wrote:
> Christophe Charron wrote:
> >On 14 août, 10:31, Neil <n...@parkwaycc.co.uk> wrote:
>
> >>In this case, you have to add load event listeners to all your frames so that when a document loads you can add all your other event listeners to their windows.
>
> >I tried, here
> >http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_13...

> >but it doesn't seem to work !
>
> You didn't add the other event listeners to the window, you added it to
> the frame element (which doesn't work). Try fa_aay(window.toto); instead.
Yesssss !!!
It works perfectly.

http://test03.christophe-charron.org/public/xul/2007_08_09/2007_08_14_test01_en.xul

A very very big thanks.

Best regards,
Christophe

Reply all
Reply to author
Forward
0 new messages