Noob question...

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

    Noob question...

    Hi fellas. I have a problem. I am trying ot get a popup window to appear
    in the center of the screen, both vertically and horozontally. I am trying
    to display a large version of an image in this window... but the image size
    varies. I now have to know the size of the image before I can center it
    properly. So, this is the code I am using.

    fnFullView = function () {
    var _mediumLargeIma ge = new Image();
    _mediumLargeIma ge.src = arPhotolog[currIndex].full
    var screenX = screen.width
    var screenY = screen.height
    var source = arPhotolog[currIndex].full
    var h = _mediumLargeIma ge.height - 10
    var w = _mediumLargeIma ge.width
    var myOtherWindow =
    open("","fullvi ew","toolbar=0, location=0,dire ctories=0,statu s=1,menubar=0,s c
    rollbars=0,resi zable=0,width=" + w+ ",height="+ h);

    cWidth = w
    cHeight = h

    abs_x = (screenX-cWidth)/2
    abs_y =(screenY-cHeight)/2

    myOtherWindow.d ocument.write(' <HTML><HEAD><TI TLE>www. Q Z M I C R O
    ..com</TITLE></HEAD><BODY ONBLUR="self.cl ose();" TOPMARGIN="0"
    MARGINHEIGHT="0 " LEFTMARGIN="0" MARGINWIDTH="0" ><IMG ID="popUpImage " SRC='+
    source+ ' BORDER="0" HEIGHT='+ h+ ' WIDTH='+ w+ '></BODY></HTML>');
    myOtherWindow.d ocument.close() ;
    myOtherWindow.m oveTo(abs_x,abs _y);
    }

    Now... My question is.... is this the standard for setting the image height
    and width of an image to a variable? Why won't this script work on Netscape
    7 or Opera 7? Mozilla 1.5 won't work either. Thanks guys. Let me know if
    I need to explain my problem in further detail...

    Tony Vasquez (Qzmicro)


  • Lasse Reichstein Nielsen

    #2
    Re: Noob question...

    "Tony Vasquez" <condorschool@e arthlink.net> writes:
    [color=blue]
    > I am trying ot get a popup window to appear in the center of the
    > screen, both vertically and horozontally.[/color]

    <soapbox>
    Don't. There are far too many problems associated with that.

    If the browser is MDI (Multiple Document Interface) then each page
    is a document window inside a single application window (like Word).
    In that case, you don't have access to the entire screen, and trying
    to center wrt. the screen will most likely end up placing parts
    of your window outside the viewable area of the application.

    If the user has multiple monitors arranged as one big desktop, your
    window will probably be placed with one half on each screen.

    Let the browser place the window, it knows better than you where
    there is room for the window.

    (and then there is the problem that any popup suffers from: popup
    blockers).
    </soapbox>
    [color=blue]
    > fnFullView = function () {
    > var _mediumLargeIma ge = new Image();
    > _mediumLargeIma ge.src = arPhotolog[currIndex].full
    > var screenX = screen.width
    > var screenY = screen.height[/color]

    You should use screen.availWid th and screen.availHei ght.
    [color=blue]
    > var source = arPhotolog[currIndex].full
    > var h = _mediumLargeIma ge.height - 10
    > var w = _mediumLargeIma ge.width[/color]

    Image loading is asynchroneous. You can't be sure that the image
    has loaded when you get to here, so you might end up with w==0 and
    h==-10.
    [color=blue]
    > var myOtherWindow =
    > open("","fullvi ew","toolbar=0, location=0,dire ctories=0,statu s=1,menubar=0,s c
    > rollbars=0,resi zable=0,width=" + w+ ",height="+ h);
    >
    > cWidth = w
    > cHeight = h[/color]

    Why rename perfectly good variables? And why is cWidth, cHeight, abs_x
    and abs_y not local variables?
    [color=blue]
    > abs_x = (screenX-cWidth)/2
    > abs_y =(screenY-cHeight)/2[/color]
    ....[color=blue]
    > myOtherWindow.m oveTo(abs_x,abs _y);[/color]

    If you insist on placing the window, you can put
    "left="+abs_x+" ,top="+abs_y"
    in the config string of the open call.
    [color=blue]
    > Now... My question is.... is this the standard for setting the image height
    > and width of an image to a variable?[/color]

    No, you need to wait for the image to load. The best way to do that, is
    to make an "onload" handler on the image element. Then do everything
    that depends on the image in that handler.
    [color=blue]
    > Why won't this script work on Netscape
    > 7 or Opera 7? Mozilla 1.5 won't work either.[/color]

    "won't work" is not much of an error report to go on.
    What happens, exactly?

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • David Dorward

      #3
      Re: Noob question...

      Tony Vasquez wrote:
      [color=blue]
      > Hi fellas. I have a problem. I am trying ot get a popup window to appear
      > in the center of the screen, both vertically and horozontally.[/color]

      Oh wonderful. The centre of my "screen" is split across two monitors. Of
      course my Window Manager knows this and places new windows in sensible
      places (if allowed to do its job).
      [color=blue]
      > I am trying to display a large version of an image in this window... but
      > the image size varies.[/color]

      Why not reuse the existing window? Perhaps something loosely based on

      [color=blue]
      > I now have to know the size of the image before I can center it
      > properly. So, this is the code I am using.
      >
      > fnFullView = function () {
      > var _mediumLargeIma ge = new Image();[/color]

      Are variable names allowed to start with an underscore in JavaScript?
      (That's not retorical, I really don't know).
      [color=blue]
      > _mediumLargeIma ge.src = arPhotolog[currIndex].full[/color]

      Where are you defining currIndex and arPhotolog[]?
      [color=blue]
      > var screenX = screen.width
      > var screenY = screen.height[/color]

      Why?
      [color=blue]
      > myOtherWindow.d ocument.write(' <HTML><HEAD><TI TLE>www. Q Z M I C R O
      > .com</TITLE></HEAD><BODY ONBLUR="self.cl ose();"[/color]

      So if I want to work in another window while the image is loading over my
      not very fast connection, the window goes away? Wonderful.
      [color=blue]
      > TOPMARGIN="0"
      > MARGINHEIGHT="0 " LEFTMARGIN="0" MARGINWIDTH="0"[/color]

      This is not valid HTML.


      --
      David Dorward http://dorward.me.uk/

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Noob question...

        David Dorward <dorward@yahoo. com> writes:
        [color=blue]
        > Are variable names allowed to start with an underscore in JavaScript?
        > (That's not retorical, I really don't know).[/color]

        ECMA 272, section 7.6 (Identifiers/Description)
        ---
        This standard specifies one departure from the grammar given in the
        Unicode standard: The dollar sign ($) and the underscore (_) are
        permitted anywhere in an identifier. The dollar sign is intended for
        use only in mechanically generated code.
        ---

        So, yes :)
        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Tony Vasquez

          #5
          Re: Noob question...

          Thanks guys, well... I got a better idea... can anyone help me come up
          with a quick little DIV that will become visible in the center of the
          browser area? That might be a nicer way of displaying the image anyway. I
          am not as new as I might seem, but I am still learning. Any help, no mater
          how technical is appreshiated.

          Tony Vasquez

          "Tony Vasquez" <condorschool@e arthlink.net> wrote in message
          news:CrN5b.8771 $tw6.7112@newsr ead4.news.pas.e arthlink.net...[color=blue]
          > Hi fellas. I have a problem. I am trying ot get a popup window to appear
          > in the center of the screen, both vertically and horozontally. I am[/color]
          trying[color=blue]
          > to display a large version of an image in this window... but the image[/color]
          size[color=blue]
          > varies. I now have to know the size of the image before I can center it
          > properly. So, this is the code I am using.
          >
          > fnFullView = function () {
          > var _mediumLargeIma ge = new Image();
          > _mediumLargeIma ge.src = arPhotolog[currIndex].full
          > var screenX = screen.width
          > var screenY = screen.height
          > var source = arPhotolog[currIndex].full
          > var h = _mediumLargeIma ge.height - 10
          > var w = _mediumLargeIma ge.width
          > var myOtherWindow =
          >[/color]
          open("","fullvi ew","toolbar=0, location=0,dire ctories=0,statu s=1,menubar=0,s c[color=blue]
          > rollbars=0,resi zable=0,width=" + w+ ",height="+ h);
          >
          > cWidth = w
          > cHeight = h
          >
          > abs_x = (screenX-cWidth)/2
          > abs_y =(screenY-cHeight)/2
          >
          > myOtherWindow.d ocument.write(' <HTML><HEAD><TI TLE>www. Q Z M I C R O
          > .com</TITLE></HEAD><BODY ONBLUR="self.cl ose();" TOPMARGIN="0"
          > MARGINHEIGHT="0 " LEFTMARGIN="0" MARGINWIDTH="0" ><IMG ID="popUpImage "[/color]
          SRC='+[color=blue]
          > source+ ' BORDER="0" HEIGHT='+ h+ ' WIDTH='+ w+ '></BODY></HTML>');
          > myOtherWindow.d ocument.close() ;
          > myOtherWindow.m oveTo(abs_x,abs _y);
          > }
          >
          > Now... My question is.... is this the standard for setting the image[/color]
          height[color=blue]
          > and width of an image to a variable? Why won't this script work on[/color]
          Netscape[color=blue]
          > 7 or Opera 7? Mozilla 1.5 won't work either. Thanks guys. Let me know[/color]
          if[color=blue]
          > I need to explain my problem in further detail...
          >
          > Tony Vasquez (Qzmicro)
          >
          >[/color]


          Comment

          • David Dorward

            #6
            Re: Noob question...

            Lasse Reichstein Nielsen wrote:[color=blue]
            > David Dorward <dorward@yahoo. com> writes:[color=green]
            >> Are variable names allowed to start with an underscore in JavaScript?
            >> (That's not retorical, I really don't know).[/color]
            >
            > ECMA 272, section 7.6 (Identifiers/Description)
            > So, yes :)[/color]

            Thanks.

            --
            David Dorward http://dorward.me.uk/

            Comment

            Working...