代码描述:window.open()弹出窗口 居中显示。window.open()弹出窗口居中显示代码下载
本章节通过代码实例详细介绍一下如何让使用window.open()函数打开的页面能够居中显示。 代码实例如下:
<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="https://www.51qianduan.com/" /> <title>51前端</title> <style type="text/css"> html,body{height:100%} #antzone{ width:300px; line-height:100px; background:#CCC; font-size:12px; text-align:center; margin:0px auto; } </style> <script type="text/javascript"> var openWindow = function(url, options){ var str = ""; if (options) { options.height = options.height || 420; options.width = options.width || 550; //默认为居中 options.left = options.left || ((screen.width - options.width) / 2); //默认为居中 options.top = options.top || ((screen.height - options.height) / 2); for (var prop in options) { str += ',' + prop + '=' + options[prop]; } str = str.substr(1); }; window.open(url, 'connect_window_'+ (+new Date), str); str = null; }; window.onload=function(){ document.body.onclick = function(){ openWindow("http://www.softwhy.com/",{ width:888 }); } } </script> </head> <body> <div id="antzone">softwhy.com</div> </body> </html>
请绑定手机号,在继续操作
注意:只有绑定手机以后,才可使用网站全部功能