我有一个打开新窗口的 JavaScript 函数:
我的index.htm页面有3个链接:
<body>
<div class="nav">
<a href = "javascript:openContent('jobsearch.htm', 875, 1300, 0, 300)">Job Search</a><br />
<a href = "javascript:openContent('details.htm?page_id=7&details_id=7',875, 1300, 0, 300)">Job Details</a><br />
<a href = "javascript:openContent('apply.htm?page_id=10&details_id=7', 875, 1300, 0, 300)">Apply</a><br/>
</div>
</body>
我的openContent
函数:
function openContent(url, width, height, top, left)
{
var win;
win = window.open(url, 'content', "toolbar=no, titlebar=no, status=no, scrollbars=no, resizable=no, top=" + top + ", left=" + left + ", width=" + width + ", height=" + height + "\"");
win.focus();
}
当单击index.htm页面中的链接时,我打开特定页面,在firefox
和IE
上,窗口在同一位置打开,但在chrome
它在页面最左侧的位置打开。
有什么想法吗?
谢谢
最佳答案
出于以下原因,您应该尽量避免使用 native 弹出窗口:
- 许多浏览器默认会阻止它们。
- 每个浏览器以不同的方式呈现它们。
- 它们通常被认为很烦人。
一个好的替代方案是 jQuery UI Dialog ,这使您可以更好地控制其呈现方式。
但是,如果您坚持使用 native 弹出窗口,您可以尝试 moveTo
功能,例如:
function example() {
var win = window.open("http://stackoverflow.com/", 'content', "toolbar=no, titlebar=no, status=no, scrollbars=no, resizable=no, width=500, height=500");
win.focus();
win.moveTo(50, 50);
}
它在最新版本的 Firefox、Chrome 和 IE 中对我有用。
关于javascript - 为什么在 google chrome 中弹出窗口显示在与 firefox 和 IE 中不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23761906/