js打开新窗口并最大化

调用viceScreen.open(url),打开一个新的窗口,并是最大化的。

1、在父窗口调用子窗口方法,可以使用方法getSecondWindow(),便可以取得子窗口的引用对象,继而通过引用对象可以调用子窗口的方法了。

2、想实现双屏显示,即是在主屏打开一个新窗口,新窗口是显示在副屏的,可以通过设置window.open方法的features属性中的left为主屏的宽长度就可以,

    可参看方法viceScreenLeft()。

3、打开的子窗口默认是最大化的,可以通过设置window.open方法的features属性中的channelmode=yes,当然这个设置只能在IE下才生效的,

    如果其它浏览器,可能通过window.resizeTo(width, height)方法便可设置,width和height设置为新窗口的大小的,获取值可通过screenWidth()和screenHeight()。

4、设置新窗口的位置,如果想调整窗口的位置的话,可以调用window.moveTo(top, left)方法,其中top和left是新窗口距离顶部、距离左边的长度。

var viceScreen = {
		name : function(){
			return "secondWindow";
		},
		setSecondWindow : function(secondWindow){
			top.secondWindow = secondWindow;
		},
		getSecondWindow : function(){
			if(top.secondWindow){
				return top.secondWindow;
			}else if(opener && opener.top && opener.top.viceScreen.getSecondWindow()){
				return opener.top.viceScreen.getSecondWindow();
			}else if(parent && parent.opener && parent.opener.top && parent.opener.top.viceScreen.getSecondWindow()){
				return parent.opener.top.viceScreen.getSecondWindow();
			}
			return undefined;
		},
		open : function(url){
			var features = "top=" + this.viceScreenTop() +", left=" + this.viceScreenLeft() 
					 +", height=" + this.viceScreenHeight() +", width=" + this.viceScreenWidth()
					 +", toolbar=no, menubar=no, location=no, status=no" 
					 +", resizable=yes, scrollbars=yes, channelmode=yes";
			
			this.setSecondWindow(window.open(url, this.name(), features));
 
		},
		close : function(){
			var secondWindow = this.getSecondWindow();
			if(secondWindow && !secondWindow.closed){
				secondWindow.window.close();
				this.setSecondWindow(undefined);
			}
		},
		resizeTo : function(width, height){
			if(this.getSecondWindow()){
				this.getSecondWindow().resizeTo(width, height);
			}
		},
                moveTo : function(top, left){
                       if(this.getSecondWindow()){
				this.getSecondWindow().moveTo(top, left);
			}
                },
                refresh : function(){
                
                },
                getOpener : function(){
                      return opener.window;
                },
                viceScreenTop : function(){
                      return 0;
                },
                viceScreenLeft : function(){
                      return this.screenWidth();
                },
                viceScreenHeight : function(){
                      return this.screenHeight();
                },
                viceScreenWidth : function(){
                      return this.screenWidth();
                },
                screenHeight : function(){
                     var height;
                      if(screen && screen.availHeight){
                       height = screen.availHeight;
                       }else{
                         if($.browser.msie){
                          height = top.document.compatMode == "CSS1Compat"? 
                                   top.document.documentElement.clientHeight : top.document.body.clientHeight; 
                         }else { 
                           height = self.innerHeight; 
                         }
                       }
                       return height;
                },
                screenWidth : function(){
                    var width;
                    if(screen && screen.availWidth){
                      width = screen.availWidth;
                    }else{ 
                        if($.browser.msie){
                           width = top.document.compatMode == "CSS1Compat"? 
                                   top.document.documentElement.clientWidth : top.document.body.clientWidth; 
                        }else{ 
                           width = self.innerWidth; 
                        }
                   }
                   return width;
                }
            };
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ok060

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值