0

Is there any reason why this is not working:

Parent document

$(document).ready(function($) {
        $('.upload-media').click(function(){
            if( $(this).parent().find('iframe')[0] )
                return false;
            $(this).parent().append('<iframe class="media-iframe" src="'+this.href+'"></iframe>');
            var ifr = $(this).parent().find('iframe');
            $(document).bind('closeFrame', function(){ alert("event"); });
            return false;   
        }); 
    });

iFrame

$(document).ready(function() {
    $("#media-frame-close").click(function(){
        window.parent.$(window.parent.document).trigger('closeFrame');
        return false;
    });
});

Seems pretty straight forward, I've tried parent. instead of window.parent and that isn't working either :(

2
  • I don't have any errors, it's just not firing the alert :( Commented Feb 18, 2011 at 21:31
  • is the iframe loading? can you post the full source of the iframe? Commented Feb 18, 2011 at 22:28

2 Answers 2

2

I've not been able to find a way to access the jQuery trigger for the document, though if you do the following you can achieve the same thing.

$(document).ready(function(){
    $('.frame').click(function(){
        if( $(this).parent().find('iframe')[0] )
        {
            return false;
        }

        $(this).parent().append('<iframe class="media-iframe" src="'+this.href+'"></iframe>');

        var ifr = $(this).parent().find('iframe');

        // Adding function directly to the document rather than using jQuery.bind/trigger
        document.closeFrame = function(){ alert("event"); };

        return false;
    });
});

$(document).ready(function(){
    $("#media-frame-close").click(function(){
        window.parent.document.closeFrame();
        return false;
    });
});

Of course this pollutes the Document Object but it will do what you want.

Sign up to request clarification or add additional context in comments.

Comments

1

top.document works well from an iframe (presuming iframe has jQuery too)

$('#ID', top.document).someFunction();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.