我有一個上傳表單發佈到隱藏的iframe。我試圖從iframe的父頁面上調用一個函數,但得到錯誤「top.stopUpload不是一個函數」。如何使用jQuery從iframe的父頁面調用函數?
這樣做的正確方法是什麼?
父頁面:
$(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; ?>);
}