window对象提供的功能之窗口最大化

本文介绍了一种使用JavaScript实现网页窗口最大化的方法。通过打开一个中转页面并在其中利用window.open方法来创建一个全屏窗口,同时关闭原来的窗口。适用于需要全屏展示网页内容的应用场景。
  实现窗口最大化的基本思路是:首先打开一个“中转”页面,在该页面中用window.open方法打开一个最大化的窗口,并且在该窗口中将父窗口关闭。实例如下:
  ex3.html:
ExpandedBlockStart.gif代码
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
 3 <html xmlns="http://www.w3.org/1999/xhtml">
 4 <head>
 5     <title>ex3</title>
 6     <script type="text/javascript">
 7         // 页面加载之后打开一个新窗口,加载ex4.html
 8         function init() {
 9             var options = "status=yes,resizable=yes,left=0,top=0,width=" +
10             (screen.availWidth - 8+ ",height=" + (screen.availHeight - 56);
11             window.open("ex4.html","_blank",options);
12         }
13 
14         // 无提示关闭窗口
15         function closeWin() {
16             window.opener = null;
17             window.close();
18         }
19     </script>
20 </head>
21 <body onload="init()">
22 
23 </body>
24 </html>

  ex4.html:

ExpandedBlockStart.gif代码
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd">
 3 <html xmlns="http://www.w3.org/1999/xhtml">
 4 <head>
 5     <title>ex4</title>
 6     <script type="text/javascript">
 7         function init() {
 8             if(window.opener) window.opener.closeWin();
 9         }
10     </script>
11 </head>
12 <body onload="init()">
13 <h1>ex4</h1>
14 </body>
15 </html>

 

 

转载于:https://www.cnblogs.com/mikelin/archive/2010/02/02/1662123.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值