window.open()打开两个窗口 [英] window.open() opens two windows

查看:679
本文介绍了window.open()打开两个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

使用命名窗口作为目标,无论如何都会打开一个新窗口。另外,两个

窗口都有相同的名称。仅在某些机器上发生这种情况


env:

XP sp2

ie6.0.2900.2180

+ sp2


复制这两个文件,test1.html


< HTML>< BODY>

< script>

function openit(){

var addlookup = open(''about :blank'', ''addlookup'');

document.f1.target =" addlookup";

document.f1.submit();

}

< / script>


< form name = f1 action =" test2.html" >

< input type = button onclick =" openit();" value =" open">

< / form>


< / BODY>< / HTML>

....和test2.html


< HTML>< BODY>

< script>

函数showname(){

alert(self.name);

}

< / script>

< / HEAD>

< BODY>

点击这是查看窗口名称< input type = button onclick =" showname( );">

< / BODY>

< / HTML>


------ -


如果你使用

var addlookup = open(''test2.html'',''addlookup'');

那么你可以看到两次使用相同的名字。


我们在这里的几台机器上遇到了这个问题(大约20个中的3个),所有这些都是/>
似乎有相同的资源管理器设置。

这里的一些帖子似乎有同样的问题,但没有后续工作

帮助。


希望有人加入n帮助。

迈克

解决方案

MPH说:


问题:
使用命名窗口作为目标,无论如何都会打开一个新窗口。此外,两个窗口都具有相同的名称。这种情况发生在某些机器上只有
< script>
function openit(){
var addlookup = open(''about :blank'',''addlookup '');
document.f1.target =" addlookup";
document.f1.submit();
}
< / script>




open()方法立即返回,无需等待

窗口系统实际创建窗口。如果在某些机器上发生这种情况需要花费更长的时间,那么当您提交表单时,新窗口将不会存在
。由于

没有窗口存在名称addlookup,因此创建了一个新窗口。


setTimeout(" document.f1.submit()" ;,1000);


Lee于2005年4月28日在comp.lang.javascript中写道

MPH说:


问题:使用命名窗口作为目标,无论如何都会打开一个新窗口。此外,两个窗口都具有相同的名称。这只发生在某些机器上


< script>
function openit(){
var addlookup = open(''about :blank'',''addlookup'');
document.f1.target =" addlookup";
document.f1.submit();
}
< / script>



open()方法立即返回,无需等待窗口系统实际创建窗口。如果这种情况发生在某些机器上需要更长时间,那么当您提交表单时,新窗口仍然不存在。由于名称addlookup不存在窗口,因此创建了一个新窗口。

setTimeout(" document.f1.submit()",1000);




同样的效果可以通过以下方式实现:


< script>

function openit() {

document.f1.target =" _blank" ;;

document.f1.submit();

}

< / script>

-

Evertjan。

荷兰。

(全部替换在我的电子邮件地址中穿过圆点)





你好李,


感谢您的快速回复,但是用'setTimeout(" document.f1.submit()",1000替换

" document.f1.submit();" );",

仍会显示两个窗口。现在发生的是指定的

窗口立即出现,没有内容和完整的浏览器窗口

出现在第二个指定时间后的内容

参数settimeout()。


谢谢


MPH


** *通过开发人员指南 http://www.developersdex.com 发送***

Problem:
using a named window as target, a new window is opened anyway. Also, both
windows have the same name. This happens on SOME machines only

env:
XP sp2
ie6.0.2900.2180
+ sp2

Replicate with these two files, "test1.html"

<HTML><BODY>
<script>
function openit(){
var addlookup=open(''about:blank'',''addlookup'');
document.f1.target="addlookup";
document.f1.submit();
}
</script>

<form name=f1 action="test2.html" >
<input type=button onclick="openit();" value="open">
</form>

</BODY></HTML>

.... and "test2.html"

<HTML><BODY>
<script>
function showname(){
alert(self.name);
}
</script>
</HEAD>
<BODY>
Click this is to see window name <input type=button onclick="showname();">
</BODY>
</HTML>

--------

if you use
var addlookup=open(''test2.html'',''addlookup'');
then you can see the same name being used twice.

We''ve had this problem on a few machines here (about 3 out of 20), which all
appear to have identical explorer settings.
A few posts here seem to have the same problem but no follow ups have
helped.

Hope someone can help.
Mike

解决方案

MPH said:


Problem:
using a named window as target, a new window is opened anyway. Also, both
windows have the same name. This happens on SOME machines only <script>
function openit(){
var addlookup=open(''about:blank'',''addlookup'');
document.f1.target="addlookup";
document.f1.submit();
}
</script>



The open() method returns immediately, without waiting for the
windowing system to actually create the window. If that happens
to take a little longer on some machines, the new window won''t
exist yet when you submit the form. Since no window exists by
the name "addlookup", a new one is created.

setTimeout("document.f1.submit()",1000);


Lee wrote on 28 apr 2005 in comp.lang.javascript:

MPH said:


Problem:
using a named window as target, a new window is opened anyway. Also, both
windows have the same name. This happens on SOME machines only


<script>
function openit(){
var addlookup=open(''about:blank'',''addlookup'');
document.f1.target="addlookup";
document.f1.submit();
}
</script>



The open() method returns immediately, without waiting for the
windowing system to actually create the window. If that happens
to take a little longer on some machines, the new window won''t
exist yet when you submit the form. Since no window exists by
the name "addlookup", a new one is created.

setTimeout("document.f1.submit()",1000);



The same effect can be reached by just:

<script>
function openit(){
document.f1.target="_blank";
document.f1.submit();
}
</script>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)




Hi Lee,

Thanks for your quick response, however on replacing
"document.f1.submit();"with "setTimeout("document.f1.submit()",1000);",
two windows are still displayed. What happens now is that the specified
window appears straight away with no content and a full browser window
appears with the content after the time specified in the second
parameter of settimeout().

Thanks

MPH

*** Sent via Developersdex http://www.developersdex.com ***


这篇关于window.open()打开两个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆