SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast jared's Avatar
    Join Date
    Sep 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help with capturing .onResize

    This code is for a popup that will display a screenshot. I would like the user to be able to resize the window, but not have the window wider or longer than the picture.

    However, I do not know how to capture the .onResize so that the script executes...

    window.onResize="resizeme()"

    Code:
    <script type="text/javascript">
    <!--
    function resizeme() {
    var mywin
    if ($pic_sizex == self.width && $pic_sizey == self.height)
    {
    window.resizeto("$pic_sizex*$factor, $pic_sizey*$factor")
    }
    
    else if ($pic_sizex*$factor > self.width)
    {
    window.resizeto = ("window.width, $pic_sizey*$factor")
    }
    else ($pic_sizey*$factor > self.height)
    {
    window.resizeto = ("$pic_sizex*$factor, window.height")
    }
    }
    // -->
    </script>
    thanks again for your help, it is always appreciated,

    jared
    signature

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    although i have never used it, my javascript book says that onResize should be an attribute of the <body> or the <frameset> tag. It says that it will be invoked when the window is resized. In your case, assuming that your function works, this should do what you want:

    <body onResize="resizeme();">

    or

    <frameset onResize="resizeme();">

    let us know if this works.

  3. #3
    SitePoint Enthusiast jared's Avatar
    Join Date
    Sep 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks for the reply, but...

    ok, the popup is called via the following and the variables are passed to it:

    popupwin=window.open('ssf.php?ssurl='+ssurl+'&pic_sizex='+pic_sizex+'&pic_sizey='+pic_sizey+'&factor='+factor......

    I placed the code in the ssf.php doc, in the <frameset tag>. However, when I resize, I'm getting a "$pic_sizex is undefined error".... But the window gets resized back...

    Can I share variables from javascrip to php & back to javascript like this? Or is there an additional step?

    It seems I am almost there as the function is getting called on a resize, but javascript doesn't know what the values are for the variables.

    thanks for your help, I do appreciate you taking the time to help,

    jared
    signature

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i should have looked at your function more carefully. You can't share variables between php and javascript in the way that you are trying to do it. what you can do is dynamically write javascript using php. For example, you would want to do something like this, assuming that you are working with a php file and these variables have already been declared globally. Where you have:

    var mywin
    if ($pic_sizex == self.width && $pic_sizey == self.height)
    {
    window.resizeto("$pic_sizex*$factor, $pic_sizey*$factor")
    }

    You will need to use javascript variables but you can set them with php:

    var mywin;
    var iPicSizeX = <?php echo $pic_sizex ?>;
    var iPicSizeY = <?php echo $pic_sizey ?>;
    var iFactor = <?php echo $factor ?>;
    var iResizeX = iPicSizeX * iFactor;
    var iResizeY = iPicSizeY * iFactor;

    if (iPicSizeX == self.width && iPicSizeY == self.height) {
    window.resizeto(iResizeX, iResizeY)
    }

    of course this also assumes that the logic behind your function is solid. see where this gets you. if you still have problems post them.

  5. #5
    SitePoint Enthusiast jared's Avatar
    Join Date
    Sep 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply, I'll give it a go.

    I'm trying to keep this as simple as possible
    - the initial function gets called with the filename & size of the picture to display
    -The javascript makes sure that the popup can't be resized wider or taller than the picture, so it's tidy.
    -The picture can be zoomed 100-200-300% as some of the screenshots are <256x256.

    that's it, that's all.

    you can see what I mean via http://dynamic3.gamespy.com/~rcatt/idex.php

    in the middle look for |ss| after the 1st paragraph and the popup will display, however it's not reizable.

    I'll play around with this - I think I just need to think about it & it'll come together.

    Thanks again for your help,

    jared
    signature

  6. #6
    SitePoint Enthusiast jared's Avatar
    Join Date
    Sep 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hmmmmm

    this doesn't seem to be working for me...

    All I want to be able to do is limit the size the window can be resized to, so that it is neither wider than the picture is wide, or taller than the picture is high.

    And I don't think I'm going about it right...

    any suggestions?

    jared
    signature

  7. #7
    JavaScript Guru (Big Ego) Arielladog's Avatar
    Join Date
    Jul 1999
    Location
    SC, USA
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    WHen assigning event handlers, like this, you need to use a function object. For instance:

    function doThis(){
    // some stuff here
    }

    window.onresize = doThis;

    Read these two tutorials:

    http://www.webmasterbase.com/article/470
    http://www.webmasterbase.com/article/473

    Following the info on those tutorials and what I've given, you could then go:

    window.onresize = new Function("//some stuff here");
    window.onresize = Function("//some stuff here");

    or (which I prefer):

    window.onresize = function(){
    //some stuff here
    }

    Hope that helps,
    aDog

  8. #8
    SitePoint Enthusiast jared's Avatar
    Join Date
    Sep 2001
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks for the reply

    OK, the code currently looks like this:
    Code:
    <script type="text/javascript">
    <!--
    function resizeme() {
    var mywin; 
    var j_x = <?php echo("$pic_sizex"); ?>; 
    var j_y = <?php echo("$pic_sizey"); ?>; 
    var j_factor = <?php echo("$factor"); ?>; 
    var j_rx = j_x*j_factor
    var j_ry = j_y*j_factor+18+36+36
    
    if (self.width > j_rx)
    {
    			window.resizeTo = ("j_rx, self.height")
    }
    else (self.height > j_ry)
    {
    		  window.resizeTo = ("self.width, j_ry")
    }
    }
    // -->
    </script>
    I don't get any errors, but the window size doesn't get limited either... from looking through the code, for example, trying to make the window taller should resize it back to the proper size, but it doesn't happen.

    The onResize="resizeme(); is in the frameset tag of the top frame.

    very bothersome... but thanks to you both for helping me out. The java guides from netscape don't shed any light on this either.

    jared
    signature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •