That's good - if it were a different domain we'd be in trouble!

I forgot to ask, but the JavaScript function you want to intercept is a
global function in the iframe, correct? Then you could use something like
this plugin (untested):

    ;(function( $ ) {
        $.fn.frameHook = function( name, hook ) {
            this.each( function() {
                var win = this.contentWindow;
                var target = win[name];
                win[name] = function() {
                    hook.apply( win, arguments );
                    return target.apply( win, arguments );
                };
            });
        };
    })( jQuery );

Given an iframe with id="myframe" and a global function inside the iframe
named 'foobar', you would do:

    $('#myframe').frameHook( 'foobar', function() {
        alert( 'about to call foobar' );
    });

To help illustrate, here's a bare metal version without the jQuery
boilerplate:

    function frameHook( iframe, name, hook ) {
        var win = iframe.contentWindow;
        var target = win[name];
        win[name] = function() {
            hook.apply( win, arguments );
            return target.apply( win, arguments );
        };
    }

    var iframe = $('#myframe')[0];
    frameHook( iframe, 'foobar', function() {
        alert( 'about to call foobar' );
    });

-Mike

> From: Luiz Abrahao
> Michael, thanks for your time,
> 
> It's loaded form the same domain.
> 
> > On Jul 3, 3:41 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> > Is the iframe loaded from the same domain as the containing 
> > page, or a different domain?
> >
> > > From: Luiz Abrahao
> > > I have one page with one iframe, and there are few javascript 
> > > function on the page inside the iframe. These functions are 
> > > triggered by some flash presentations.
> > >
> > > Basically the parent page has to 'know' when the user has 
> > > requested the next page (inside the iframe) and update its content
> > > with relevant data related with this new page inside the iframe.
> > >
> > > I can't change the javascript functions from the pages inside the 
> > > iframe.

Reply via email to