2011-03-08 38 views
0

我將目標表單提交給iFrame。現在,當我嘗試獲取iFrame的innerHTML時,我得到空值。這裏是我的代碼:獲取iFrame的更新值

<form name="upload_form" action="" method="post" target="upload_target"> 
//----- other tags 
</form> 
<iframe id="upload_target" name="upload_target" src=""></iframe> 

該操作返回一個id值,它將被設置爲iFrame。之後,當我嘗試獲取iFrame的innerHTML時,它顯示爲空。在UI中,我可以看到iFrame中的id值。

JS代碼:

alert(document.getElementById("upload_target").innerHTML); 

我怎樣才能從價值的的iFrame ID?

回答

0

您應該使用contentWindow屬性存取權限的iframe內容:

document.getElementById('upload_target').contentWindow.document.documentElement.innerHTML 
0

可以返回調用在parrent窗口的回調函數html頁面:

<html> 
<head runat="server"> 
    <title>Upload Result</title> 
</head> 
<body> 
    <script type="text/javascript"> 
     window.onload = function() { 
      var fn = parent['uploadSuccess']; 
      if (fn) { 
       fn(<fileId>); 
      }    
     }; 
    </script> 
</body> 
</html> 

而在parrent窗口:

window['uploadSuccess'] = function(fileId) { 
    // do something with the fileId 
}