js打开新窗口,js打开居中窗口,js打开自定义窗口

2022-10-10,,,,

================================

©copyright 蕃薯耀 2020-01-07

 

var isie=!!window.activexobject;      //是否ie浏览器
var isie6=isie&&!window.xmlhttprequest;  //是否ie6浏览器
var isie7=isie&&!isie6&&!isie8;  //是否ie7浏览器
var isie8=isie&&!!document.documentmode;  //是否ie8浏览器
var availheight = screen.availheight;    //默认高度为屏幕的高度
if(isie8){  
    availheight= screen.height;
}
//ie11升级弹出窗口小
if (!!window.activexobject || "activexobject" in window){
    availheight= screen.height;
}
 
/**********************************************************************************
*函数名称: 打开新窗口
*功能说明: 通过传递参数打开一个定制的新窗口,
*参数说明:
 surl:        url地址 
 windowname   弹出窗口的名字(不是文件名),非必须,可用空''代替; 
 iheight      窗口高度; 
 iwidth       窗口宽度; 
 itop         窗口距离屏幕上方的象素值; 
 ileft        窗口距离屏幕左侧的象素值; 
 stoolbar     是否显示工具栏,yes为显示; 
 smenubar     是否显示菜单栏,yes为显示;
 sscrollbars  是否显示滚动栏,yes为显示; 
 sresizable   是否允许改变窗口大小,yes为允许; 
 slocation    是否显示地址栏,yes为显示; 
 sstatus      是否显示状态栏内的信息(通常是文件已经打开),yes为显示;
***********************************************************************************/    
    
function opencustomwindow(surl,windowname,itop,ileft,iwidth,iheight,stoolbar,smenubar, sscrollbars,sresizable,slocation, sstatus)
{
window.open (surl, windowname, 'height='+iheight+', width='+iwidth+', top='+itop+', left='+ileft+', toolbar='+stoolbar+', menubar='+smenubar+', scrollbars='+sscrollbars+',resizable='+sresizable+',location='+slocation+', status='+sstatus) 
}



/**
 * 打开一个居中的窗口
 * @param pageurl url链接
 * @param innerwidth 宽度,不带px,小于0表示百分比
 * @param innerheight 高度,不带px,小于0表示百分比
 */
function openwindowcenter(pageurl, innerwidth, innerheight){
    var screenwidth = screen.availwidth;
    var screenheight = screen.availheight;
    var width = screenwidth;
    var height = screenheight;
    
    if(innerwidth < 1){
        width = screenwidth * innerwidth;
        screenwidth = (screen.availwidth - width)/2;
    }else{
        width = innerwidth;
        screenwidth = (screen.availwidth - innerwidth)/2;
    }
    if(innerheight < 1){
        height = screenheight * innerheight;
        screenheight = (screen.availheight - height)/2;
    }else{
        height = innerheight;
        screenheight = (screen.availheight - innerheight)/2;
    }
    window.open(pageurl, "", "left=" + screenwidth + ",top=" + screenheight +",width=" + width + ",height=" + height + ",resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
};

/**
 * 打开一个居中的窗口,可有滚动条
 * @param pageurl url链接
 * @param innerwidth 长度,不带px
 * @param innerheight 宽度,不带px
 */
function openwindowscroll(pageurl, innerwidth, innerheight){
    var screenwidth = (screen.availwidth - innerwidth)/2;
    var screenheight = (screen.availheight - innerheight)/2;
    window.open(pageurl, "", "left=" + screenwidth + ",top=" + screenheight +",width=" + innerwidth + ",height=" + innerheight + ",resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
};


/**
 * 打开一个居中的窗口,可变大小
 * @param pageurl url链接
 * @param innerwidth 长度,不带px
 * @param innerheight 宽度,不带px
 */
function openwindowresizable(pageurl, innerwidth, innerheight){
    var screenwidth = (screen.availwidth - innerwidth)/2;
    var screenheight = (screen.availheight - innerheight)/2;
    window.open(pageurl, "", "left=" + screenwidth + ",top=" + screenheight +",width=" + innerwidth + ",height=" + innerheight + ",resizable=yes,scrollbars=no,status=no,toolbar=no,menubar=no,location=no");
};

 

 

(如果你觉得文章对你有帮助,欢迎捐赠,^_^,谢谢!) 

 

================================

©copyright 蕃薯耀 2020-01-07

 

《js打开新窗口,js打开居中窗口,js打开自定义窗口.doc》

下载本文的Word格式文档,以方便收藏与打印。