Is it possible to observe events in iframe?
var iframe = new Element('iframe');
iframe.observe('mouseup', function (e) { ... }); // Not works ;-(
I found that in FF, I can
iframe.contentWindow.document.addEventListener('mouseup', function (e)
{...}, true); // Works
But, how to do it with Prototype?
tnx
on 2008-06-24 14:54
on 2008-06-24 15:00
Not exactly. As you can see from your example, the iframe's content is literally a different document, with its own namespace. So if Prototype were loaded in the iframe's document, you could say iframe.contentWindow.document.observe(...). -Fred On Tue, Jun 24, 2008 at 7:53 AM, AlannY <m@alanny.ru> wrote: > {...}, true); // Works > > But, how to do it with Prototype? -- Science answers questions; philosophy questions answers.
on 2008-06-24 15:04
You should observe the window inside the frame, the code is something
like this:
function contentWindow(frame){
if(Prototype.Browser.IE)
return frame.contentWindow.document;
return frame.contentDocument.defaultView;
}
contentWindow = contentWindow($('my_frame'));
Event.observe(contentWindow, 'click', function(e){/*...*/});
--
blog: www.lucaguidi.com
Pro-Netics: www.pro-netics.com
Sourcesense - making sense of Open Source: www.sourcesense.com
on 2008-06-25 17:08
Is Prototype loaded to the iframe automaticaly, or I should load manually? If second: how to do it?
on 2008-06-25 17:08
contentWindow.observe isn't a function because A) it's in the other frame and you haven't loaded Prototype into it, and B) because the window object probably isn't extended anyway. The code below uses Event.observe(...contentWindow), not contentWindow.observe(). -Fred On Wed, Jun 25, 2008 at 10:03 AM, AlannY <m@alanny.ru> wrote: > > Firefox says: > contentWindow.observe is not a function ;-) Like before ;-( -- Science answers questions; philosophy questions answers.
on 2008-06-25 17:09
The body of the iframe document would need to have the <script> tag for
Prototype.
-Fred
On Wed, Jun 25, 2008 at 10:07 AM, AlannY <m@alanny.ru> wrote:
> > -Fred
--
Science answers questions; philosophy questions answers.
on 2008-06-25 17:17
As Frederick said, you cannot invoke #observe on contentWindow, because it isn't a Prototype extended element. You should use Event.observe syntax. Luca -- blog: www.lucaguidi.com Pro-Netics: www.pro-netics.com Sourcesense - making sense of Open Source: www.sourcesense.com
on 2008-06-25 17:28
I was playing with #extendIframe method some time ago http://github.com/kangax/protolicious/tree/master/... Unfortunately, it only works in FF/Safari (need to find some time to tackle the problems in IE/Opera) - kangax
on 2008-06-25 21:16
Be cautious of listening to the iframe's document, if that iframe refreshes, its a brand new document, and in that case your listener is lost, so you'd have to listen to the load event and grab a fresh reference to stay persistent. -- Matt Foster Ajax Engineer Nth Penguin, LLC http://www.nthpenguin.com
on 2008-06-26 17:54
Still not works ;-(
var iframe_doc;
if( Prototype.Browser.IE ) {
iframe_doc = iframe.contentWindow.document;
} else {
iframe_doc = iframe.contentDocument.defaultView;
}
Event.observe(iframe_doc, 'click', function (e) { alert("click"); });