window.open到屏幕中心 [英] window.open to center of screen
问题描述
我正在使用window.open打开一个弹出窗口,如下所示:
I am using window.open to open a popup window like so:
< a href =http:// path / to / urlonclick =window.open(this.href,'sharegplus','height = 485,width = 700'); return false; target =_ blank>
我想让它在屏幕中居中,但不必使用 <脚本>内联代码< / script>
,只需在 onclick =
中输入我需要的内容。可以这样做吗?
I want this to be centered in the screen, but without having to use <script> inline code </script>
and merely enter whatever I need within onclick=""
. Can this be done?
推荐答案
编辑
这是一个坏事回答。可以在这里找到一个更好的答案:
window.open() - 窗口弹出窗口在哪里?
但与此同时,当我决定何时更新这个答案时,这个小提琴会考虑双显示器设置: http:/ /jsfiddle.net/w665x/138/
But in the meantime while i decide when i want to update this answer, this fiddle accounts for dual monitor setups: http://jsfiddle.net/w665x/138/
这可能适合你。不完全是跨浏览器,但关闭;
This might work for you. Not confident in it being entirely cross-browser, but close;
<html>
<head>
<script type="text/javascript">
function goclicky(meh)
{
var x = screen.width/2 - 700/2;
var y = screen.height/2 - 450/2;
window.open(meh.href, 'sharegplus','height=485,width=700,left='+x+',top='+y);
}
</script>
</head>
<body>
<a href="http://path/to/url" onclick="goclicky(this); return false;" target="_blank">blah</a>
</body>
</html>
这篇关于window.open到屏幕中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!