js打开新窗口并最大化

来源:互联网 发布:elect镜头数据 编辑:程序博客网 时间:2024/06/08 12:01

调用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;                }            };




0 0
原创粉丝点击