0

ポップアップを作成したいのですが、ブラウザーや画面サイズに関係なく、常に中央に配置したいと考えています。

そのために、window.innerWidth を使用していますが、このコードが機能しない理由がわかりません。

function show_update_profile()
   {
       document.getElementById('black_fade').style.display='block';
       alert(window.innerWidth);
       document.getElementById('div_register').style.display='block';
       document.getElementById.('div_register').style.left= ((window.innerWidth)-500)/20;
       alert(window.innerWidth);
   }

回線document.getElementById.('div_register').style.left= ((window.innerWidth)-500)/20;に問題があります。

4

1 に答える 1

0

window.innerWidthクロスブラウザ互換性がないため、すべてのブラウザで動作するとは限らないため、このような機能が必要です

function getBrowserInnerSize(w)
{
    var x,y;
    if (!w){
        w = window;
    }

    if (w.innerHeight){ 
        // FireFox
        x = w.innerWidth;
        y = w.innerHeight;
    } else if (w.document.documentElement && w.document.documentElement.clientHeight) {
        // IE Strict mode
        x = w.document.documentElement.clientWidth;
        y = w.document.documentElement.clientHeight;
    } else if (w.document.body) {
        // IE Normal mode
        x = w.document.body.clientWidth;
        y = w.document.body.clientHeight;
    }

    return {"x":x,"y":y};
}
于 2012-04-09T08:04:34.180 に答える