javascript - 为什么在 google chrome 中弹出窗口显示在与 firefox 和 IE 中不同的位置

标签 javascript html internet-explorer google-chrome firefox

我有一个打开新窗口的 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页面中的链接时,我打开特定页面,在firefoxIE上,窗口在同一位置打开,但在chrome 它在页面最左侧的位置打开。

有什么想法吗?

谢谢

最佳答案

出于以下原因,您应该尽量避免使用 native 弹出窗口:

  1. 许多浏览器默认会阻止它们。
  2. 每个浏览器以不同的方式呈现它们。
  3. 它们通常被认为很烦人。

一个好的替代方案是 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/

相关文章:

html - 哪些HTML元素是可标签的

css - 与 Firefox/Chrome 相比,IE 中的蓝图站点完全不同

html - 为什么IE9进入兼容模式时span + :first-letter + text-transform:capitalize?

javascript - 文本不会出现在 html 页面上

javascript - 使用 Javascript 和 Ajax 的 Rails 开发环境

javascript - 如何将超时变量分配给 Vuetify 中的 <v-alert> 标签?

php - 查找文本将占用多少行

javascript - Bootstrap 灯箱不工作

html - 如何更改 jQuery 动画中的文本颜色?

javascript - 给 HTML 时间来呈现其文本