虚拟主机域名注册-常见问题网络编程问题 → JS


js弹出窗口居中 window.open()弹出居中的窗口
作者:
<a href="#" onclick="openwin()">专业的网站建设公司</a>

js代码如下

function openwin() {
var height=450;//必须
var width=600;//必须
var top=Math.round((window.screen.height-height)/2);  
var left=Math.round((window.screen.width-width)/2);  
window.open('http://www.sinmeng.net','newwindow','toolbar=no,scrollbars=yes,resizable=no,top='+top+',left='+left+',width=600,height=450')
}


或者使用如下代码

<a href="javascript:void(0);" onclick="javascript:openwindow('http://www.sinmeng.net','',400,200);">梦搏网络专业的网站建设公司</a>


js代码如下:

var url; //转向网页的地址;
var name; //网页名称,可为空;
var iWidth; //弹出窗口的宽度;
var iHeight; //弹出窗口的高度;
var iTop = (window.screen.availHeight-30-iHeight)/2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth-10-iWidth)/2; //获得窗口的水平位置;
window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');




来源:
阅读:1809
日期:2016-09-13

推荐朋友 】 【 评论 】  【 字体: 】 
上一篇:齐博cms后台栏目不显示或显示不全 栏目数超过500个
下一篇:html表格边框双线显示成单线的解决方法
  >> 相关文章
 
发表评论


点  评: 字数0
用户名:  密码:

  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款