function openNewWindow(url, name, customWidth, customHeight) { // 设置宽高的默认值
if(!customWidth) {
customWidth=window.screen.width/1.5;
}
if(!customHeight) {
customHeight=window.screen.height/1.5;
} //window.screen.height获得屏幕的高,window.screen.width获得屏幕的宽
var iTop = (window.screen.height - 30 - customHeight) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.width - 10 - customWidth) / 2; //获得窗口的水平位置;
window.open(url, name, 'height=' + customHeight + ',innerHeight=' + customHeight + ',width=' + customWidth + ',innerWidth=' +customWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=no,resizeable=no,location=no,status=no');
}
调用
<button class="submit" onclick="openNewWindow('url','窗口标题','宽','高')">我要应聘</button>
评论区