How to call function on parent page from iframe using jQuery?

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2011-11-30T01:46:22Z Indexed on 2011/11/30 1:50 UTC
Read the original article Hit count: 150

Filed under:
|
|
|

I have an upload form that posts to a hidden iframe. I am attempting to call a function on the parent page from the iframe, but am getting the error "top.stopUpload is not a function".

What is the correct way to do this?

PARENT PAGE:

$(document).ready(function() {

    $('#document_upload').submit( function() {

        $('#upload_progress').show();

     });

    function stopUpload(success){

        if (success == 1){
            $('#result', window.parent.document).html(
            '<span class="msg">The file was uploaded successfully!<\/span>');
        }

        else {
            $('#result', window.parent.document).html(
            '<span class="emsg">There was an error during file upload!<\/span>');
        }

        $('#upload_progress').hide();

        return true;

    }

})

IFRAME:

$(document).ready(function() {

   top.stopUpload(<?php echo $result; ?>);

}

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX