ホームページ  >  記事  >  ウェブフロントエンド  >  JavaScript — ウィンドウ オブジェクトの使用例_基礎知識

JavaScript — ウィンドウ オブジェクトの使用例_基礎知識

WBOY
WBOYオリジナル
2016-05-16 17:09:591100ブラウズ

ウィンドウ オブジェクトは、JavaScript ブラウザ オブジェクト モデルの最上位オブジェクトであり、複数の共通メソッドとプロパティが含まれています。

1 新しいウィンドウを開きます

コピーcode コードは次のとおりです:

window.open(pageURL,name,parameters)

ここで:

pageURL は子ウィンドウのパスです

name は子ウィンドウのハンドルです

パラメータはウィンドウパラメータです (各パラメータはカンマで区切られます)

例:
コードをコピーします コードは次のとおりです:

window.open("http://www.cnblogs .com/zhouhb/","open",'height =100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=いいえ');

2 モーダルウィンドウを開きます
コードをコピーします コードは次のとおりです:

window.showModalDialog("http://www.cnblogs.com/zhouhb/","open","toolbars=0;width=200;height=200"); >
3 プロンプト ボックスをポップアップ表示せずにウィンドウを閉じます

スクリプト プログラム (window.open()) を通じて Web ページを開いていない場合は、window.close() を呼び出す前にスクリプトを実行してウィンドウを閉じるには、window.opener オブジェクトを null に設定する必要があります。そうでない場合、ブラウザ (IE7、IE8) は閉じることを確認するダイアログ ボックスが表示されます。

コードをコピー コードは次のとおりです:


or



フレームウィンドウを閉じる場合


コードをコピー コードは次のとおりです: <スクリプト言語="JavaScript">
closefunctionWindow()
{
window.opener = null;
window.parent. close();
}



4 つの位置オブジェクトは



コードをコピーします
コードは次のとおりです: window.location.reload();// 現在のページを更新しますwindow.location.href="http://www. cnblogs.com/zhouhb/"; / /他のページをロードします

5 履歴オブジェクトは



コードをコピー
を使用します コードは次のとおりです。 window.history.go(1); //Forwardwindow.history.go(-1); //Backward

6 子フォームから親ウィンドウへボディ渡しの値

6.1 簡単なメソッド

(1) 親フォームで子フォームを開く




コードをコピーします
コードは次のとおりです。 var str=window.showModalDialog("s.html"); (str!=null) {
var v=document.getElementById("v");
v.value =str;


(2)サブフォーム コード



コードをコピー

さらに、showModalDialog によって開かれたウィンドウに対して、また、dialogArguments を通じて値を渡すこともできます:

親ウィンドウ コード:



コードをコピー


コードは次のとおりです。





無題ドキュメント

(2) 開くwindow




コードをコピー

コードは次のとおりです。
;META http-equiv="Content -Type" content="text/html; charset=gb2312"> ウィンドウ演習


アカウント情報:
アカウントを正しく保管してください。紛失を避けるため。
アカウント:

パスワード:






6.2 より詳細な紹介

ご存知のとおり、window.open() 関数は次のようになります。新しいウィンドウを開くために使用されますが、子フォームから親フォームに値を渡すとき、実際には window.opener を通じて親フォームへの参照を取得できます。
たとえば、新しいフォーム FatherPage.htm を作成する場合:




コードをコピーします

コードは次のとおりです:



Then in ChildPage.htm, you can access the elements in the parent form through window.opener:
Copy code The code is as follows:





In fact, while opening the subform , we can also assign values ​​to elements of the subform, because the window.open function will also return a reference to the subform, so FatherPage.htm can be modified to:
Copy code The code is as follows:




By judging whether the reference of the subform is empty, we can also control it to open only one subform:
Copy the code The code is as follows:





This alone is not enough. When closing the child form, the child variable of the parent form must also be cleared. Otherwise, after opening the child form Once closed, it cannot be reopened:
Copy code The code is as follows:






声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。