1

I have code in 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 Script open new window (file zoom.html) and resize it o X and Y of image (url varriable). But problem is that new window displays in the upper right corner of the screen and also goes out of the screen. How to display window in the middle of the screen?

1 Answers1

0

This should do the trick!

{
    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);
}
Graham Robertson
  • 808
  • 5
  • 10