windows.opener的应用
来源:互联网 发布:手机淘宝怎么取消代付 编辑:程序博客网 时间:2024/05/29 18:23
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>a.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <script language="JavaScript"> function openWin(){ /* * window.open ( sURL , sName , sFeatures , bReplace ) * * sURL: 指定要被加载的HTML文档的 URL 地址 * * sName:_blank: 在新窗口中打开 sUrl * * sFeatures:指定窗口装饰样式 多个之间用逗号隔开 */ window.open("a2.html","_blank",'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no'); }function setValue(cid,cname){document.getElementById("cid").value=cid; document.getElementById("cname").value=cname;} </script> <body> <form name="form1" action="test.html" method="post" > <input type="text" name="cid" value="" id="cid" > <input type="text" name="cname" value="" id="cname" > <input type="button" name="ok" value="请选择客户" onclick="openWin();"/> </form></body> </html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>a2.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <script language="JavaScript"> function viewData(cid,cname){//如何获取a1.html页面的引用 window.opener//调用a1.html页面的setValue函数 window.opener.setValue(cid,cname); //不再引用父窗口 window.opener=null; //关闭当前窗口 window.close();} </script> <body> <table border="1"> <tr> <td>操作</td><td>客户id</td><td>客户名称</td> </tr> <tr> <td><input type="button" value="选择" id="ss" onclick="viewData('001','深圳华为')"></td><td>001</td><td>深圳华为</td> </tr> <tr> <td><input type="button" value="选择" onclick="viewData('002','用友软件')"> </td><td>002</td><td>用友软件</td> </tr> </table> </body> </html>