1

我在js中有代码:

<script>
function displayWindow(url, w, h)
{
  var win = window.open("zoom.htm","displayWindow",'width='+w+', height='+h+',resizable=yes,scrollbars=yes,menubar=no' );
  win.document.write("<html><body onclick=window.close()>");
  win.document.write("<img id=fullimg src=" + url+">");
  win.document.write("</body></html>");
  var image = win.document.getElementById("fullimg");
  win.resizeTo(image.width + 50, image.height + 50);
}
</SCRIPT>

Java 脚本打开新窗口(文件 zoom.html)并将其调整为图像的 X 和 Y(url 变量)。但问题是新窗口显示在屏幕的右上角并且也离开了屏幕。如何在屏幕中间显示窗口?

4

1 回答 1

0

这应该可以解决问题!

{
    var win = window.open(
            "zoom.htm", "displayWindow", 'width=' + w +
            ', height='+ h +', resizable=yes, scrollbars=yes, menubar=no');
    win.document.write("<html><body onclick='window.close();'>");
    win.document.write("<img id='fullimg' src=" + url + ">");
    win.document.write("</body></html>");
    var image = win.document.getElementById("fullimg");

    var width = image.width + 50;
    var height = image.height + 50;
    win.resizeTo(width, height);
    win.moveTo((screen.width - width) / 2, (screen.height - height) / 2);
}
于 2013-05-31T16:15:21.853 回答