Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize function 2

Status
Not open for further replies.

micawber

Programmer
Dec 10, 2002
71
GB
I use the code below to resize my popup windows.
I would like to change it so that if the open window is already larger that the current size, it doesn't do anything.
Can anyone help?

Code:
<script type="text/javascript">  
  ResizeTo(100, 100);
</script>


function ResizeTo( intWidth, intHeight) {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			top.outerWidth=intWidth;
			top.outerHeight=intHeight;
		}
		if (navigator.appName=="Safari") {
			self.resizeTo(screen.availWidth=960,screen.availHeight=700);
			top.outerWidth=intWidth;
			top.outerHeight=intHeight;
		}
	else top.resizeTo(intWidth,intHeight);
	}
}
 
You get the current size of the window by:

Code:
var windowWidth = 0;
var windowHeight = 0;
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  windowWidth = window.innerWidth;
  windowHeight = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  windowWidth = document.body.offsetWidth;
  windowHeight = document.body.offsetHeight;
 }
}

I think you can take it from there.
 
I just remembered... the code I provided is from frames without scrollbars. If you have scrollbars:

Code:
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  windowWidth = window.innerWidth-16;
  windowHeight = window.innerHeight-16;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  windowWidth = document.body.offsetWidth-20;
  windowHeight = document.body.offsetHeight-20;
 }
}
 
I was just trying to give a quick and easy answer without really doing much thinking.

But I will look into that article regardless.
 
I'm still unable to find a solution so that if i open a window at a larger size (i.e. 1000 x 800 pixels) the resize function set at 960 x 700 pixels doesn't do anything.

I need it so the resize only works if the window opened is smaller.
 
Well i can't seem to get anything to work so i still have the code from my original post.
 
If I use the rough logic layout in your original script, and that I allow myself to deliberately overlook 16-20 px or so not-so-relevant details for this functionality, I would do something like this, imperfect as it is.
[tt]
function ResizeTo[blue]_2[/blue]( intWidth, intHeight) {
//under the condition: allowing imprecision of 16-20 px or so not-so-relevant details
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape" || navigator.appName=="Safari") {
var w=top.outerWidth;
var h=top.outerHeight;
if (w>intWidth && h>intHeight) {
top.outerWidth=intWidth;
top.outerHeight=intHeight;
}
} else if (navigator.appName.indexOf("Microsoft")!=-1) {
var w = document.body.offsetWidth;
var h = document.body.offsetHeight;
if (w>intWidth && h>intHeight) {
top.resizeTo(intWidth,intHeight);
}
} else { //some uncertainty?
top.resizeTo(intWidth,intHeight);
}
}
}
[/tt]
Maybe you can improve based on it?
 
Thanks for your help.
I'm still unable to get anything to work.
Does anyone know a way around this?
Thanks.
 
Around this? Around what? except that [a] I might misunderstand the criteria or the inverse of it. So you may change larger than (>) to less than (<) which might be what you have in mind; don't forget to call it with _2 suffix, if not, just named the function the same name (ResizeTo) rather than ResizeTo_2.
 
micawber,

Why don't you show us what you've tried for yourself, whether it has worked or not?

Right now, we've no idea what you are doing, or what you've tried, and it may well be that you're trying the right thing in the wrong context, or have syntax errors, or maybe you're just trying to get us to write code for you. We simply have no idea as saying "it doesn't work" gives nothing away.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes, basically when I say I'm unable to get this to work, I am saying I have tried the recent function provided by tsuji. It doesn't work for me. I'm calling the function by the correct name and criteria looks correct to me.
I have tried removing and altering lines without success too.
Thanks for your help.
 
I have various links across sites, here is an example:

Code:
<area shape="rect" coords="8,14,239,48" href="JavaScript:void(0);" onClick="MM_openBrWindow('[URL unfurl="true"]https://www.test.com/popup.asp','Popup','status=yes,scrollbars=yes,resizable=yes,width=1000,height=960');">[/URL]

the (link/page) has the following:

Code:
<script type="text/javascript" src="..\functions.js"></script>
- functions.js is where the resize function is stored from the initial post.
Code:
<!-- #include file="../inc_resize2.asp" -->
-The code below is held in the inc_resize2.asp file.
Code:
<script type="text/javascript">  
  Resize2(960, 720);
</script>
 
Put the line like this.
[tt] window.onload=function() {Resize2(960, 720);}[/tt]
Or if you've already an window onload handler, insert that line in there.
 
Thanks Tsuji.
I've changed the line so it looks like this, i don't have an onload handler:
Code:
<script type="text/javascript">  
	window.onload=function() {Resize2(960, 720);}
</script>
I don't notice any difference though.
 
Also make the slash forward.
><script type="text/javascript" src="..\functions.js"></script>
[tt]<script type="text/javascript" src="..[highlight]/[/highlight]functions.js"></script>[/tt]
But as you said Resize2() resides in the ssi, so the above just might have an indirect impact.
 
Thanks, I've given that a go, changing the slash forward unfortunately it doesn't change anything.
Thanks.
 
If the original simple resize function works as advertised in your stuffy page, then the elaborated resize function should not result in simple observation: "not work" - at least not in ie and ff/netscape. Does the original resize functionality work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top