ナビ

新規ウィンドウをサイズ指定のセンター表示する

wrote :

「test.html」をサイズ500×500(px)、新規ウィンドウ、画面中央で開くと仮定

function newWinIconOpen(URL){
var hidari=(screen.width-500)/2;
var ue=(screen.width-500)/2;
var newWinIcon;
newWinIcon = window.open(URL,"test",#quot;location=no, menubar=no, resizable=yes, scrollbars=no, status=no, width=500, height=500, left='+hidari+', top='+ue+' ");
newWinIcon.focus();
}

ポイントは、topとleftの記述が肝(変数の左右に「+」を記述し、「"」でくくること。以下に上で作成したスクリプトをhtmlファイルに記述する方法を一応紹介。

<a href="javascript:newWinIconOpen(test.html);">スクリプト実行<a>

問題は、確かxhtml1.0のscriptでは「href="javascript:SCRIPT();"」という記述の仕方にエラーが出たような気がしたのだが。現状未確認だが判明し次第このファイルを更新します。