私はJSの私のサイトにファイルアップロードのコードを持っています:
function detectDone(){
done++;
var _ifrWallp = document.getElementById("ifrWallp");
var html = _ifrWallp.contentWindow.document.body.innerHTML;
if (html.indexOf('File name:') != -1) {
// Done
uploadedWall();
} else {
setTimeout('detectDone()',10);
}}
および HTML:
<div id="addWallpp" class="addMWallp" style="float: left;" onmouseover="document.getElementById('uploadDesc').style.display = 'block'; document.getElementById('ifrWallp').contentWindow.document.getElementById('wpmain').style.backgroundColor = '#FFF7C0';" onmouseout="document.getElementById('uploadDesc').style.display = 'none'; document.getElementById('ifrWallp').contentWindow.document.getElementById('wpmain').style.backgroundColor = '#F9F9F9';">
<iframe id="ifrWallp" onload="Upload('../')" scrolling="no" frameborder="0" style="text-align:center;vertical-align:middle;border-style:none;margin:0px;width:100%;height:45px" src="sources/private/upload.php"></iframe>
そしてphpファイルのいくつかのコード。IEではエラーはありませんが、chromeとfirefoxではエラーが発生します:
var html = _ifrWallp.contentWindow.document.body.innerHTML;
キャッチされていない TypeError: null のプロパティ 'innerHTML' を読み取れません
そしてFFで:
TypeError: _ifrWall.contentWindow.document.body が null です
ページが読み込まれた後に iframe コードを読み込む必要があることはわかっていますが、残念ながら、ファイルのアップロードで機能させる方法がわかりません。助けてください :(