admin管理员组文章数量:1570425
一、Js打开新窗口并居中显示
HML部分:
<button onclick="openNewWindow('https://www.baidu')">打开百度</button>
JS部分:
/*
功能:打开新得浏览器窗口并居中显示
参数:
url:需要打开的url地址
name:打开的窗口名称,可以为null
customWidth:窗口的宽度
customHeight:窗口的高度
*/
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=auto,resizeable=no,location=no,status=no');
}
效果:
版权声明:本文标题:JS打开新窗口并居中显示 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1727669809a1125047.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论