當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS打开新窗口并居中显示
生活随笔
收集整理的這篇文章主要介紹了
JS打开新窗口并居中显示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、Js打開新窗口并居中顯示
HML部分:
<button onclick="openNewWindow('https://www.baidu.com')">打開百度</button>JS部分:
/*功能:打開新得瀏覽器窗口并居中顯示參數:url:需要打開的url地址name:打開的窗口名稱,可以為nullcustomWidth:窗口的寬度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打开新窗口并居中显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bzoj3195 [Jxoi2012]奇
- 下一篇: Mongoexport导出数据,Mong