---
title: "一个从另一个打开页面返回值的javascript例子"
author: "ericjoe"
date: "2007-11-16T14:52:00Z"
tags: []
slug: "javascript"
draft: false
lastmod: "2007-11-16T14:52:00Z"
id: 393837
url: "https://coffeef.iteye.com/blog/393837"
---

今天写项目的时候用到了需要从另一个打开页面取值的javascript，觉得很有用，就把它简化成了一个简单的例子贴出来，有小区的可以看看，有谁有更好的给小弟仍一个。  
  用两个页面进行测试：      
1，访问页面：a.html：

&lt;html&gt;  
&lt;head&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;input type="text" name="name" id="name" &gt;  
&lt;input type="button" value="选择用户"  
  onclick="window.open('b.html','selectname',800,600,1);"&gt;  
&lt;/body&gt;  
&lt;/html&gt;  
2，新打开的选择页面b.html  
&lt;html&gt;  
&lt;head&gt;  
&lt;script type="text/javascript"&gt;  
function selectOrg(name){  
 if(window.opener){  
  window.opener.document.all.name.value =name;  
  window.close();  
}  
}  
&lt;/script&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;input type="radio" name="name" onclick="selectOrg('李四')"&gt;李四  
&lt;input type="radio" name="name" onclick="selectOrg('张三')"&gt;张三  
&lt;input type="radio" name="name" onclick="selectOrg('王五')"&gt;王五  
&lt;/body&gt;  
&lt;/html&gt;

试一下吧！