본문 바로가기

개발하자/자바스크립트

주소선택해서 이전창으로 불러오기

a.html

=========================================

<html>
 <head>
 <script>
 window.onload=function(){
 b.onclick=function(){
 newWin=window.open("bb.html","nw","");
 }
 }
 </script>
 </head>
 <body>
 <input type="text" id="t">
 <input type="button" id="b" value="주소검색">
 </body>
</html>

 

bb.html

===================================================

<html>
 <head>
 <script>
 window.onload=function(){
 var array=["진주시","창원시","마산시"];
var buffer=[];

 for(var i=0; i<3; i++){
 buffer.push("<a href=# onclick=sel('"+array[i]+"')>"+array[i]+"</a><br>");
 }
 con.innerHTML=buffer.join("");
 b.onclick=function(){
window.opener.document.getElementById("t").value=t.value;
 }
 }
 function sel(v){
 t.value=v;
 }
 </script>
 </head>
 <body>
 <div id="con"></div>
 <input type="text" id="t">
 <input type="button" id="b" value="확인">
 </body>
</html>