[zuoyefeng.com]
用window.opener实现页面值传递
[日期]: 2006-04-19  [来源]: www.zuoyefeng.com  [作者]: 昨夜风

文件一:111.htm,在c:/inetpub/wwwroot/test1/下
<html>
<head>
<script language=javascript>
function Goto2(){
window.open('http://localhost/Search/223.html');
}
</script>
</head>
<body>
<input type="text" id="test" name="test">
<input type="button" onclick="Goto2()" value = "test Click">
</body>
</html>
文件二:223.html(在c:/inetpub/wwwroot/Search下)
<html>
<head>
<script language = javascript>
function Change() {
alert(window.opener.name);
window.opener.document.getElementById('test').value = "111";
}
</script>
</head>
<body>
<input type="button" onclick="Change()" value="test_2" >
</body>
</html>
结果在111.htm中弹出223.htm后,点击test_2按钮出错。
而如果我把它们放到同一个项目中,就可以。请问为什么?
有解决方案吗?




为了安全起见,js把这种访问限制在同一个域中。
所以基本上没有办法!




function Change() {
alert(opener.name);
opener.document.getElementById('test').value = "111";
}




js不可以跨域访问。
如果你的两个域有相同的上级域,并且浏览支持的话,可以使用document.domain属性
参看http://blog.csdn.net/lhelper/archive/2003/08/11/18720.aspx




window.open('../search/223.html');p


阅读:
录入:jinyinghui

评论 】 【 推荐 】 【 打印
上一篇:查找当前页面某字符的javascript
下一篇:建立iframe自适当网页
相关信息