老孟!来拿分!给你的!

kobe_lee 2001-08-06 02:45:05
我按你的说法写了一对父子窗口,为什么子窗口不能调用父窗口的自定义对象的方法?

parent.html
//////////<html>
<head>
<title>PARENT AND CHILD WINDOWS</title>
<script language='JavaScript'>
var newwin=new newwin();
function newwin(alertmess){
this.alertmess=alertmess;
}
function alertmess(){
window.alert('success!');
}
</script>

</head>
<body BGCOLOR="#c0c0c0">
<a href="child.html" target="newindow">Create a child window</a><br>
<input type='submit' onclick=alertmess()>
</body>
</html>



child.html
//////////
<html>
<head>
<script language='javascript'>
function getParent(){
window.opener.newwin.alertmess();
}
</script>
<title>PARENT AND CHILD WINDOWS</title>
</head>
<body>

<input type='submit' value='get parent message' onclick=getParent()>

</body>
</html>

请你一定帮我!

...全文
109 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
kobe_lee 2001-08-06
  • 打赏
  • 举报
回复
搞定了!多谢老孟!
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
我的IE4就行的啊,你试试我贴的代码。拷贝过去
kobe_lee 2001-08-06
  • 打赏
  • 举报
回复
我原来就是这么写的,我又试了一下,可还是不行啊!
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
function newwin(){
this.alertmess=alertmess;
}
kobe_lee 2001-08-06
  • 打赏
  • 举报
回复
你是说我的parent.html里的自定义对象有问题?
如果是应该怎么改啊?!
我很着急!
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
你那是调用opener的函数
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
不用删除,我给了2个帖子,都可以的。关键是你定义的有问题
kobe_lee 2001-08-06
  • 打赏
  • 举报
回复
当前的源文件:
parent.html
////////////
<html>
<head>
<title>PARENT AND CHILD WINDOWS</title>
<script language='JavaScript'>
function alertmess(){
window.alert('success!');
}
function newwin(){
This.alertmess=alertmess();
}

newwin=new newwin();
</script>

</head>
<body BGCOLOR="#c0c0c0">

<a href="javascript:void(window.open('child.html'))">Create a child window</a><br>
<input type='submit' onClick=alertmess()>
</body>
</html>

child.html
//////////////

<html>
<head>
<script language='javascript'>

function getParent(){
if(window.opener.newwin==null){
alert("newwin is null!");
}
window.opener.alertmess();
}
</script>
<title>PARENT AND CHILD WINDOWS</title>
</head>
<body>
<form name='newwindow'>
<input type='submit' value='get parent message' onClick=getParent()>
</form>
</body>
</html>
kobe_lee 2001-08-06
  • 打赏
  • 举报
回复
还是不行啊!
如果把子窗口里中window.opener.newwin.alertmess();里的newwin删掉就可以,
window.opener.alertmess();
这是为什么?
我自己定义的对象中的方法定义有问题吗?
麻烦给看看!
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
也可以这样:
<html>
<head>
<title>PARENT AND CHILD WINDOWS</title>
<script language='JavaScript'>
var newwin=new newwin();
function newwin(){
this.alertmess=alertmess;
}
function alertmess(){
window.alert('success!');
}

</script>

</head>
<body BGCOLOR="#c0c0c0">
<a href="javascript:void(window.open('child.html'))">Create a child window</a><br>
<input type='submit' onclick=alertmess()>
</body>
</html>
=======
<html>
<head>
<script language='javascript'>
function getParent(){
window.opener.newwin.alertmess();
}
</script>
<title>PARENT AND CHILD WINDOWS</title>
</head>
<body>

<input type='submit' value='get parent message' onclick=getParent()>

</body>
</html>
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
<html>
<head>
<title>PARENT AND CHILD WINDOWS</title>
<script language='JavaScript'>
var newwin=new newwin();
function newwin(alertmess){
this.alertmess=alertmess;
}
function alertmess(){
window.alert('success!');
}
</script>

</head>
<body BGCOLOR="#c0c0c0">
<a href="javascript:void(window.open('child.html'))">Create a child window</a><br>
<input type='submit' onclick=alertmess()>
</body>
</html>

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

<html>
<head>
<script language='javascript'>
function getParent(){
window.opener.alertmess();
}
</script>
<title>PARENT AND CHILD WINDOWS</title>
</head>
<body>
<input type='submit' value='get parent message' onclick=getParent()>
</body>
</html>
孟子E章 2001-08-06
  • 打赏
  • 举报
回复
child.html必须是window.open()打开的才行

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧