#779 bug
Ngan

Custom event firing with document from iFrame issues

Reported by Ngan | August 28th, 2009 @ 01:16 AM

Hi I came an issue with Firefox (works for Safari and IE8 correctly)
RE: Event.observe(...) vs ___.observe(...). You'll need both of the
files below.

Notice that firefox only receives the fire when it is using "observe"
directly on the iframe's document element. Whereas Event.observe does
not work. Safari and IE8 picks up both observes and prints out both
messages to console.

FILE: test.html

<html> 
<head> 
  <script src="js/prototype.js" type="text/javascript"></script> 
  <script> 
Event.observe(window, 'load', function() { 
  $('ifr').writeAttribute('src', 'test2.html'); 
}); 

function register(ifrDocument) { 
  ifrDocument.observe('custom:event', function() { 
    console.info('received fire 1'); 
  }); 
  Event.observe(ifrDocument, 'custom:event', function() { 
    console.info('recieved fire 2'); 
  }); 
} 
  </script> 
</head> 
<body> 
<iframe id="ifr"></iframe> 
</body> 
</html>

FILE: test2.html

<html> 
<head> 
  <script src="js/prototype.js" type="text/javascript"></script> 
  <script> 
Event.observe(window, 'load', function() { 
  parent.register(document); 
  console.info('firing event from iframe...'); 
  document.fire('custom:event'); 
}); 
  </script> 
</head> 
<body> 
</body> 
</html>

Comments and changes to this ticket

  • Diego Perini

    Diego Perini August 30th, 2009 @ 08:36 PM

    • Tag set to event, observe

    Ngan,
    please be more specific about the version of Firefox on which you observed this misbehavior.

    I have tested the code above in FF 3.0.12 and FF 3.5.1 and it works for me in both browsers.

    Actually I can see "received fire 1" and "received fire 2" in the console, the difference for Firefox in respect to other browsers is that this happens twice, I mean the "custom:event" is fired twice so I see 4 "received fire X".

    This happens when you reload the page with "Command-R" on my Mac, because of you injecting the "src" attribute during the "onload" event of the main document. When you load the page by giving ENTER in the URL this does not happen.

    If you put the "src" attribute in the iframe, instead of injecting it, itself everything work as expected.

    -- Diego

  • Ngan

    Ngan August 30th, 2009 @ 09:28 PM

    Firefox 3.5.2 using prototype from master.

    Thanks!

  • Ngan

    Ngan August 30th, 2009 @ 09:43 PM

    Strange, I never seem to get the double (4x) received fire messages (command+R or command+L & enter).

    I tried adding the src attribute into the iframe tag, but still..same thing thing. I only get "received fire 1".

  • Diego Perini

    Diego Perini August 31st, 2009 @ 04:07 PM

    Ngan,
    sorry the behavior you described is correct, I was using prototype-1.6.0.3.js.

    Switching to latest 1.6.1RC3.js reveal the same results you have.

    firing event from iframe...
    received fire 1
    firing event from iframe...
    received fire 1
    

    Still when I use the reload button or "command+R" or even "command-L+ENTER" I get it fired twice.

    Note that I am running the examples from a local "file:///" protocol and not from an "httpd" server, this can make a difference, please describe if you are running the examples from local or from remote server.

    For the Prototype team, I would like to be able to extend an iframe with Prototype but without having to reload it again in the iframe. Is this possible or will this be possible in a future release ?

    Something like this will be useful:

    PrototypeBind(document);
    

    -- Diego

  • Ngan

    Ngan August 31st, 2009 @ 05:31 PM

    Note that I am running the examples from a local "file:///" protocol and not from an "httpd" server, this can make a difference, please describe if you are running the examples from local or from remote server.

    I'm using a httpd server.

  • Tobie Langel

    Tobie Langel September 1st, 2009 @ 02:08 AM

    • Tag changed from event, observe to section:dom

    For the Prototype team, I would like to be able to extend an iframe with Prototype but without having to reload it again in the iframe. Is this possible or will this be possible in a future release ?

    That's planned for 2.0

  • T.J. Crowder

    T.J. Crowder November 16th, 2009 @ 04:50 PM

    [responsible:none bulk edit command]

  • Tisho Georgiev

    Tisho Georgiev March 1st, 2010 @ 04:03 PM

    • State changed from “new” to “bug”

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages