0

私は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 コードを読み込む必要があることはわかっていますが、残念ながら、ファイルのアップロードで機能させる方法がわかりません。助けてください :(

4

1 に答える 1

1

ここで説明とコード サンプルを参照してください: http://www.sitepoint.com/forums/showthread.php?405244-InnerHTML-and-Firefox

基本的に contentWindow は IE のものです。FF の場合、contentDocument を使用する必要があります。

//ff
if (_ifrWallp.contentDocument){
var html=_ifrWallp.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
}
//ie
else if (_ifrWallp.contentWindow){
var html=_ifrWallp.contentWindow.document.body.innerHTML;
 }

// if (html.indexOf('File name:') ... etc
于 2013-09-08T15:18:39.390 に答える