yzx99

导航

 

某个网页需要多个地方用window.open的方式打开,每个地方的语句都要写上打开窗口的位置、大小以及其它参数。
如:1.htm代码:
<html>
<body>
<input id="But1" type="button" onclick="window.open('2.htm', '_blank', 'width=200, height=200, resizable=no, top=200, left=400');" />
<input id="But2" type="button" onclick="window.open('2.htm', '_blank', 'width=200, height=200, resizable=no, top=200, left=400');" />
</body>
</html>
2.htm代码:
<html>
<body>
示例
</body>
</html>
一旦该网页的大小或位置要变动,造成修改的地方较多。

后来想到在2.htm中装载时进行设置,代码如下:
1.htm代码:
<html>
<body>
<input id="But1" type="button" onclick="window.open('2.htm', '_blank', 'resizable=no');" />
<input id="But2" type="button" onclick="window.open('2.htm', '_blank', 'resizable=no');" />
<!-- 至少要带一个resizable,使用空串则是正常的一个网页 -->
</body>
</html>
2.htm代码:
<html>
<script language="javascript">
window.resizeTo(200, 200);
window.moveTo(200, 400);
</script>
<body>
示例
</body>
</html>
这样,是可以达到只在本网页设置大小,其它网页只管调用就行。但有一个缺点,即会明显的刷新。

后来再想弹出窗口时把它移到天外,这样就可以避免刷新问题。试的时候发现top值不能设为负值,只能设成极大。
1.htm代码:
<html>
<body>
<input id="But1" type="button" onclick="OpenNewWin('2.htm');" />
<input id="But2" type="button" onclick="OpenNewWin('2.htm');" />
<script language="javascript">
//在新窗口打开链接,但没有工具栏等内容
function OpenNewWin(URL)
{
  window.open(URL, "_blank", "resizable=no, top=10000");
}
</script>
</body>
</html>
这样就可以达到自己的要求了。

如果用showModelessDialog,弹出的窗口总是在前面,不太满意。

posted on 2008-12-27 11:06  yzx99  阅读(1514)  评论(1编辑  收藏  举报