この記事では、JavaScriptブラウザウィンドウ間でデータを渡す方法について説明します。参照のためにそれを共有してください。特定の分析は次のとおりです。
まとめ:
プロジェクト開発では、ポップアップウィンドウに遭遇することがよくあります。ポップアップ効果をシミュレートするためにDIVを使用し、iFramesを使用する人もいれば、ウィンドウを使用してウィンドウを開いてウィンドウを介して新しいウィンドウを開く人もいます。今日は、window.open()関数を介した最後のタイプのデータインタラクションを共有します。最初にレンダリングを見てください:
原理:
親ウィンドウによって子ウィンドウに渡されたデータは、URLのパラメーターに渡され、親ウィンドウによって子ウィンドウに渡されたデータは、親ウィンドウのグローバル機能に渡されます。
コード:
index.htmlは次のとおりです。
次のようにコードをコピーします:<!doctype html>
<html lang = "en">
<head>
<メタcharset = "utf-8">
<title> document </title>
</head>
<body>
<div id = "content"> </div>
<ボタンID = "test">ボタン</button>
<スクリプト>
var test = document.getElementById( 'test');
test.onclick = function(){
window.open( './ window.html?param1 =name¶m2= password'、 '_blank'、 'width = 960、height = 650、no、toolbar = no、no、no、no、no、status = no、no、no、yes、yes、resizable = yes');
};
window.getContent = function(tx){
document.getElementById( 'content')。innertext = tx;
}
</script>
</body>
</html>
window.htmlは次のとおりです。
次のようにコードをコピーします:<!doctype html>
<html lang = "en">
<head>
<メタcharset = "utf-8">
<title> document </title>
</head>
<body>
<div id = "content"> </div>
<name = "" id = "city">を選択します
<オプション値= "上海">上海</option>
<オプション値= "hangzhou"> hangzhou </option>
</select>
<スクリプト>
var params = location.href.substring(location.href.lastindexof( '?')+1).split( '&');
document.getElementById( 'content')。innertext = params;
var city = document.getElementById( 'City');
city.onchange = function(){
window.opener.getContent(city.value);
}
</script>
</body>
</html>
注:ここで実行するサービス環境があります
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。