need help opening a window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MM

    need help opening a window

    I am using the following code to display an image in a seperate
    window.

    <form>
    <input type=button
    onClick='window .open("image1.j pg","","width=2 60,height=260,r esizable=0,bord er=0")'
    value=Shhow Picture'>
    </form>

    I want the window to be the exact size of the image so I set the width
    and height of the window the same as the width & height of the image.

    The code works, however there is a white border on the top and left
    side of the image. If I add 20 to the width and height of the window
    then there is a white border around the whole image.

    Is there anyway to have the window the exact size of the image,
    without this white border? I know there is probably a simple solution,
    but I'm a beginner at JavaScript.

    Any help is much appreciated.


  • juglesh

    #2
    Re: need help opening a window


    "MM" <canadianhuman@ yahoo.ca> wrote in message
    news:jvkot0dlpq du73ciicqvdriv5 kqc2uta08@4ax.c om...[color=blue]
    >I am using the following code to display an image in a seperate
    > window.[/color]

    do you really need a new window? I think "thumbnail> big image in new
    window" is a pita. also, pop up blockers will block you.

    sorry to not answer your ?.


    Comment

    • RobG

      #3
      Re: need help opening a window

      MM wrote:[color=blue]
      > I am using the following code to display an image in a seperate
      > window.
      >
      > <form>
      > <input type=button
      > onClick='window .open("image1.j pg","","width=2 60,height=260,r esizable=0,bord er=0")'
      > value=Shhow Picture'>
      > </form>
      >
      > I want the window to be the exact size of the image so I set the width
      > and height of the window the same as the width & height of the image.[/color]

      You can't reliably do this for all browsers. Some automatically put a
      margin of 20px or so on all <body> tags by default. Some also add it
      when showing just an image, but others not. Safari adds it when
      showing a page, but not when showing an image.

      Even if you manage to set the margin to 0, some browsers will leave a
      border on the other side of the image (IE on Mac). So the simplest
      solution is to put all your images into HTML documents and load those
      (setting margin to 0).

      Another solution is to leave a good margin of say 50px around the
      image and set your background to some compatible colour (black seems to
      be the most common choice). For an image of width 300 and height 200,
      create a window of an extra 100px and add 50px padding to the image:

      <script type="text/javascript">
      function showPic(t,u,w,h ) {
      w -= -100;
      h -= -100
      newWin = window.open('', '','height=' + h + ',width=' + w);

      var sHTML = [
      '<html><head><t itle>' + t + '</title></head><body',
      ' style=\'margin: 0; background-color: black;',
      ' color: black;\'><img src=\'' + u + '\'',
      ' alt=\'\' border=\'0\' style=\'padding : 50 0 0 50\'>',
      '</body></html>'
      ];

      newWin.document .write(sHTML.jo in(''));
      newWin.document .close();
      }
      </script>

      </head><body>

      <form action="">
      <input type="button" value="Show Picture" onClick="
      showPic('A Picture','image 1.jpg','300','2 00');
      ">
      </form>

      Incidentally, pop-up blockers will normally allow pop-ups in response
      to user actions, but some allow even those to be blocked. Some also
      allow exceptions for certain sites.

      But in general, pop-ups are bad.

      --
      Rob

      Comment

      Working...