window.open()重复打开窗口的问题

mz24 2003-05-18 04:20:35
调用如下的函数打开了一个名为"HideWin"的窗口,这个窗口没有关掉。当第二次调用这个窗口(用的是另一个URL),发现没有效果,不能替换掉原来的内容,也没有新开窗口,请文是什么原因?如何才能替换掉原来的内容?

function OpenHideWin(theURL)
{
if (hPopup == "")
{
hPopup = window.open("", "HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
window.focus();
hPopup.resizeTo(screen.availWidth, screen.availHeight);
}
hPopup.location = theURL;
}
...全文
1249 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
mz24 2003-05-25
  • 打赏
  • 举报
回复
stanely,行吗?
我记得我试过的,结果“hPopup.resizeTo(screen.availWidth, screen.availHeight);”这个句子就没效果了,据说是javascript无法控制一个已经打开了输入流的窗口,我只好先置空,再用“hpopup.location=theURL;”来连接。

你再试试看你那样做“hPopup.resizeTo(screen.availWidth, screen.availHeight);”这个句子有没有效果?
stanely 2003-05-24
  • 打赏
  • 举报
回复
为什么要通过设置hpopup.location呢?
window.open的第一个参数设置url就可以阿,因为window.open第二个参数是不变的,只会打开一个窗口。

如下:

function OpenHideWin(theURL)
{
var hPopup = window.open(theURL, "HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
hPopup.blur();
hPopup.resizeTo(screen.availWidth, screen.availHeight);

}
mz24 2003-05-24
  • 打赏
  • 举报
回复
我发现原因了!我把函数重新写成
function OpenHideWin(theURL)
{
var hPopup = window.open("", "HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
hPopup.blur();
hPopup.resizeTo(screen.availWidth, screen.availHeight);
hPopup.location = theURL;
}
我发现只要第一次的连接的加载过程完成,再调用这个函数就可以直接替换原来的内容。但是如果第一次的加载(比如还有一个图片没有下载完)还没有完成,第二次调用这个函数就没有任何效果。

请问高手如何在用javascript中止第一次加载并使得第二次的调用有效???
javafish 2003-05-23
  • 打赏
  • 举报
回复
我也需要解决这个问题。看了一下 fason(【阿信(你是我的温柔)】) 的发言。搞定了
在这里谢谢了
fason 2003-05-22
  • 打赏
  • 举报
回复 1
window.open的第二个参数是句柄,相同的话就只能打开一个
kingofbird 2003-05-22
  • 打赏
  • 举报
回复
错了!!!重发
楼主的hPopup.location = theURL;应该是hPopup.location.href = theURL;
按的需要,不用这么复杂,可以直接实现
打开第一个
window.open("第一个连接","HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
打开第二个
window.open("第二个连接","HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
只要窗口名相同再次OPEN时就可以直接替换!
kingofbird 2003-05-21
  • 打赏
  • 举报
回复
楼主的hPopup.location = theURL;应该是hPopup.location.href = theURL;
按的需要,不用这么复杂,可以直接实现
打开第一个
window.open("第一个连接","HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
打开第二个
window.open("第二个连接","HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
对其做操作时可以用 HideWin.location.href='';
ffs 2003-05-20
  • 打赏
  • 举报
回复
这个没错,\\就是表示\,第一个\是用来转义的
mz24 2003-05-19
  • 打赏
  • 举报
回复
是没问题
但是我的调用是OpenHideWin('http:\/\/www.xxx.com\/xxx\/xxx')
有时候可以的
今天我看别人的代码,应该是这样的OpenHideWin('http://www.xxx.com/xxx/xxx')
到底要不要\?
我发现要了(有时)行,不要也行呀?

mz24 2003-05-19
  • 打赏
  • 举报
回复
本来我是不用的,后来我在用indexOf这个函数时,发现包含'\'的字符串如果不预先写成'\\'就会找不到。
例如,
var str="C:\\WINNT";
var tmp=str.indexOf("\\");
如果任一个"\\"写成'\'都会得不到预想的结果
ffs 2003-05-19
  • 打赏
  • 举报
回复
不要\的
反斜杠是在老的浏览器版本用的
那时要写成这样
document.write("<\/br>")
现在在字符串里面很多情况下不用\了
至少在你的这种情况不用
ffs 2003-05-18
  • 打赏
  • 举报
回复
你的函数没有问题啊,我试过了,下面是代码,但是如果你在点击第一个链接之后把这个窗口关掉了,那么之后你在点击第二个链接也没有用的。
<html>
<head>
<script>
var hPopup=""
function OpenHideWin(theURL)
{

if (hPopup=="")
{
alert("hpopup=")
hPopup=window.open("", "HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
window.focus();
hPopup.resizeTo(screen.availWidth, screen.availHeight);
}
hPopup.location = theURL;
}
</script>
</head>
<body>
<a href="javascript:OpenHideWin('001.htm')">the first</a>
<br>
<a href="javascript:OpenHideWin('002.htm')">the second</a>
</body>
</html>
possible_Y 2003-05-18
  • 打赏
  • 举报
回复
function OpenHideWin(theURL)
{
hPopup = window.open(theURL, "HideWin", "width=1,height=1,copyhistory=1,location=1,status=1,toolbar=1,directories=1,menubar=1,scrollbars=1,resizable=1,top=0,left=0");
window.focus();
hPopup.resizeTo(screen.availWidth, screen.availHeight);
}
mz24 2003-05-18
  • 打赏
  • 举报
回复
说明,hPopup原先是置为""的

87,904

社区成员

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

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