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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maximizing window - muliple monitor problems 1

Status
Not open for further replies.

JasonDoucette

Programmer
Mar 7, 2005
4
0
0
CA
Hello, I have seen many solutions for maximizing a window with the following code:

Code:
self.moveTo(0,0);
self.resizeTo(screen.availWidth,screen.availHeight);

I have tested this with IE 6.0 and Mozilla Firefox 1.0. If this is put to use on a multiple monitor system, on a monitor with negative screen coordinates (i.e. it is to the left of the primary monitor), it will not work. The moveTo() does not move the window to the upper-left corner. In IE's case, when the window has negative coordinates, resizeTo() does not resize the window to the specified size. resizeTo() works fine in Firefox.

I should note that this code works fine on the primary monitor, and on any secondary monitor with positive screen coordinates.

Any thoughts or suggestions are appreciated.


Jason Doucette
 
How about something like:
Code:
<script language="javascript">
var iLeft = window.screenLeft; 
var iWidth = screen.availWidth;
self.moveTo(Math.floor(iLeft/iWidth) *  iWidth, 0);
self.resizeTo(screen.availWidth,screen.availHeight);
</script>
OK, this won't work if you have one monitor above another... [smile]

------
Math problems? Call 0800-[(10x)(13i)^2]-[sin(xy)/2.362x]
 
Thanks for the reply. Your method does appear to work for my specific case, where I use IE for my own personal homepage.

Unfortunately, for the general case, this is insufficient, because screenLeft / screenTop is available only in IE. screenX / screenY is their equivalent in Netscape / Mozilla, but it is not available in IE. And, like you say, it won't work if one monitor is above the other.

But, thanks for your information regardless!

Jason Doucette
 
I think both these problems are solvable - first with some browser version checks (if this then that), second with same floor() trick as for width. Dunno what will happen when two displays have different resolution - but this case is definitely exotic.

------
Math problems? Call 0800-[(10x)(13i)^2]-[sin(xy)/2.362x]
 
Yes, indeed. I thought the same thing. The only other thing that I noticed is that sometimes this algorithm will attempt to place the window in the position of a 3rd monitor, when none exists - because of the floor() trick you used. However, the browser seems to ignore this, and pushes the window into the location we desire, anyway. So, it looks like it is all good.

I have not bothered to write the full code to be compatible with all browsers, as I am only using this for my personal homepage with IE. I would never wish to maximize a window for a webpage that is publicly viewable, as the user may dislike this.

Thanks for your help and suggestions.

Jason Doucette
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top