一定時間でページ遷移
このページは移動しました。
10秒後に自動的にジャンプします。
ジャンプしない場合はコチラをクリック
周期的にリロード
ページを周期的に呼び出す場合、サーバ側からブラウザに対して自動的にページを送るということは出来ないので、ブラウザから呼び出します。
METAタグ
JavaScript
子ウィンドウから親ウィンドウの制御
子ウィンドウから親ウィンドウの要素を参照する場合は、window.opener.document.getElementById(id)で取得します。
親ウィンドウ
function showWindow(){
window.open('opener-2.html','help','width=300,height=150');
}
子ウィンドウ
function change(no){
var menu = window.opener.document.getElementById("pullmenu");
menu.selectedIndex = no;
}
サブウィンドウに出力
ドキュメントを出力する手順
(1)document.open() --- 省略可
(2)document.wirte()
(3)document.close() --- 省略不可
function subWinOpen(){
yourName = document.myForm.userName.value;
subWin = window.open("","subWin01","left=10,top=10,screenX=10,screenY=10,width=220,height=200");
subWin.document.open();
subWin.document.write("Welcome")
subWin.document.write("");
subWin.document.write("あなたのお名前は
"+yourName+"さん
ですね?
");
subWin.document.write("");
subWin.document.close()
}
サブウインドウの判定
現在のウインドウが、スクリプトが開いたのか、ユーザが開いたのかを判定するには、openerの値や型を調べます。
ユーザが開いたウインドウの場合はopenerプロパティはnullになります。
if (typeof window.opener == "object") {
// スクリプトによって開かれたサブウインドウの処理
}
全てのサブウィンドウを閉じる
他のページに移る前に全てのサブウィンドウを閉じる。
手順
(1)表示したwindowオブジェクトを配列に保存する。
(2)他のページに移った時に配列に保存された全てのwindowオブジェクトに対して、close()メソッドを呼び出す。
// ページのアンロード時に呼び出される関数closeWindowをセット
window.onunload = closeWindow;
// 表示したウィンドウを保存する配列
var newWin = new Array();
// ボタンクリック時に呼び出される関数
function showWindow(){
newWin[newWin.length]
= window.open('close-2.html', '', 'width=300,height=150');
}
// ページのアンロード時に呼び出される関数
function closeWindow(){
for(var i=0; i
他のページに移ると、サブウィンドウは消えます。
他のページ