SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: help with capturing .onResize
-
Sep 27, 2001, 23:03 #1
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>
jaredsignature
-
Sep 28, 2001, 05:56 #2
- 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.
-
Sep 28, 2001, 16:13 #3
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,
jaredsignature
-
Sep 29, 2001, 08:01 #4
- 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.
-
Sep 29, 2001, 09:39 #5
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,
jaredsignature
-
Sep 29, 2001, 23:49 #6
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?
jaredsignature
-
Sep 30, 2001, 09:18 #7
- 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,
aDogModerator at www.javascriptcity.com/forums/
-
Sep 30, 2001, 21:31 #8
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>
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.
jaredsignature
Bookmarks