您無法通過JS獲得頁面標題,但你可以區分成功錯誤: 嘗試是這樣的:
<script type="text/javascript">
var uploadStarted = false;
function OnUploadStart(){
uploadStarted = true;
}
function OnUploadComplete(state,message){
if(state == 1)
alert("Success: "+message);
else
if(state == 0 && uploadStarted)
alert("Error:"+(message ? message : "unknow"));
}
</script>
<iframe id="uploader" name="uploader" onload="OnUploadComplete(0)" style="width:0px;height:0px;border:none;"></iframe>
<form id="sender" action="/upload.php" method="post" target="uploader" enctype="multipart/form-data" onsubmit="OnUploadStart()">
<input type="file" name="files[upload]"/>
<input type="submit" value="Upload"/>
</form>
在服務器端:
/*
file: upload.php
*/
<?php
// do some stuff with file
print '<script type="text/javascript">';
if(success)
print 'window.parent.OnUploadComplete(1,"File uploaded!");';
else
print 'window.parent.OnUploadComplete(0, "File too large!");';
print '</script>';
?>
爲什麼不在結果iframe上運行一些js? 我的意思是,您可以爲頁面加載(在父級上)設置超時,並且子級(iframe)應該在父級中設置一個值。 如果該值在超時之前未設置,則iframe失敗。 – Dementic 2011-05-24 12:25:20