473,848 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I center or resize a Browser Window?

You can try this code:


<!--- filename: mypage.html ---->
<html>
....blah blah blah
<script language=JavaSc ript src=/Javascript/center.js></script>
</html>

/*************** *************** *
filename: center.js
*************** *************** **/
var xMax = screen.width, yMax = self.screen.ava ilHeight;

if (document.body. clientWidth)
{
lnBodyClientWid th=document.bod y.clientWidth
lnBodyClientHei ght=document.bo dy.clientHeight
}
else
{
lnBodyClientWid th=window.inner Width
lnBodyClientHei ght=window.inne rHeight
}

xOffset = (xMax - lnBodyClientWid th)/2, yOffset = (yMax -
lnBodyClientHei ght)/2;
self.moveTo(xOf fset,yOffset)



<!-- javascript size resize browser client width window offset move -->

Jul 23 '05 #1
3 5636
an******@hotmai l.com wrote:
You can try this code: <snip> <script language=JavaSc ript src=/Javascript/center.js></script> <snip>

In valid HTML 4 the TYPE attribute is required in an opening script tag.
The LANGUAGE attribute is deprecated, and redundant when the required
TYPE attribute is present.
var xMax = screen.width, yMax = self.screen.ava ilHeight;
Using a mixture of - screen.width - and screen.availHei ght - seems to
pre-suppose that the (a) taskbar is present on the system, that there
are no other similar desktop features (office bar) and/or that it is
(they are) located only at the top and/or bottom of the user's screen.

That is a lot of assumptions, which will be wrong in some contexts (as
desktop furniture can be user positioned).

Not to mention the assumption that - availWidth/Height - are implemented
in the environment in question and that their values are meaningful.
There is also a disregard for the nature of these values on
multi-monitor systems, where screen dimensions may be either one of the
dimensions of the smallest rectangle that can encompass all of the
monitors in use, or the dimensions of only the 'primary' monitor. in the
first case positioning in a guessed 'centre' may result in the browser
being placed over the boundary between two (or more) monitors, and/or in
(or partly in) an area of the overall desktop that is not displayable.

In the latter case the 'primary' monitor does not have to be the one on
which the user is viewing the browser, leaving any 'centring' code
possibly moving the entire browser out of immediate sight.
if (document.body. clientWidth)
It would make sense to verify that - document.body - exists before
accessing its properties, as it did not exist on older browsers so
without the test the code will error out and fail uncontrollably.

On IE, whether the - clientWidth - property reflects the width of the
viewport depends on which mode the browser is in. In 'CSS1Compat' mode
the viewport dimensions should be read from the -
document.docume ntElement - property. For other DOM browsers that switch
modes, the object from which the viewport dimensions should be read
might be either one of - documentElement - or - body -, and the object
in question may or may not switch when different modes are used.

Also, type-converting test on DOM properties that are of primitive type
(like numbers) result in false for certain values of those properties,
even when the property is defined on the system. Testing with - typeof -
is invariable more useful when properties may have primitive values when
implemented.
{
lnBodyClientWid th=document.bod y.clientWidth
lnBodyClientHei ght=document.bo dy.clientHeight
}
else
In circumstances where - document.body.c lientWidth - is undefined or
zero there is no certainty that the system will support
innerWidth/Height, so an additional test is indicated before this branch
is taken.
{
lnBodyClientWid th=window.inner Width
lnBodyClientHei ght=window.inne rHeight
}

xOffset = (xMax - lnBodyClientWid th)/2, yOffset = (yMax -
lnBodyClientHei ght)/2;
The viewport dimensions are being used here without regard for the
actual dimensions of the window. No account is being taken of the
variable, and user configurable, window chrome. Having failed to take
chrome into account, these positions will tend to overshoot the centre.
There is also no account being taken for the possibility that the window
dimensions already exceed the available screen dimensions, where the
resulting negative offset may be very inconvenient to the user (if the
browser acted upon them). And no account has been taken for taskbars and
other desktop furniture being at the top or left of the screen(s), as
that would suggest an offset for the positioning.

However, as preceding code may have failed to assign a numeric value to
either of - lnBodyClientWid th - or - lnBodyClientHei ght - verification
of an acceptable range for those values should be extended to verify
that they are meaningful numbers to start with.
self.moveTo(xOf fset,yOffset)
The window's - moveTo - method has been subject to considerable abuse
over the years so these days it is usually capable of being disabled by
users, or disabled by default.
<!-- javascript size [ ... ] offset move -->


In javascript these sequences are syntax errors, they should never
appear in an javascript file.

There a lots of things wrong with this code, and circumstances where it
will fail (to some degree or another), but you have failed to state you
question, or give any details of the problems you are actually
experiencing with the code.

Richard.
Jul 23 '05 #2
Wow Thats a lot of pounding there! But where is your solution?

Jul 23 '05 #3
an******@hotmai l.com wrote:
Wow Thats a lot of pounding there!
But where is your solution?


Solution to what? You are still to state the problem and its context.
You might try reading the group's FAQ, and related resources, on the
subject of asking questions (among other things).

Richard.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2129
by: Rob | last post by:
Hi, I have some problems resizing a html page when it is loaded. I want the page to resize to the screensize. The following snipped of code (see below) works perfect on my Windows NT. but not on my Windows 98. Windows 98 with Ms Explorer 6.0.2800.1106IS Update versions:; SP1; q313829; Q328970; Q330994; Q813389l Q818529; Q824145;
25
19987
by: chris | last post by:
how would i resize a browser window to a specific size as the page loads, using html or javascript
8
8908
by: jrefactors | last post by:
I want to maximize the browser window when I open a new window. Now I do the following, but different monitor size will yield different width and height values. window.open('index.jsp',myform.target,'toolbar=no,menubar=no,resizable=yes,scrollbars=yes,width=800,height=600'); Any ideas? please help. thanks!!
4
1852
by: jef | last post by:
I have an Intranet application that is targeted to IE browsers only. It is also designed explicitly to fit an 800x600 window. That said, I wish to ensure that the browser window sizes appropriately when they log in. I'm using this right now: <HEAD> <title>My Login Page</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript"...
33
4092
by: randau | last post by:
Linking to a Targeted Browser Window I'd like to open reference links to other web sites in a separate browser window from the browser window hosting my own web site pages. The Link Target reserve word "_blank" opens a blank new browser window for every link, which can sometimes result in a lot of open browser windows. Is there no way to "reuse" a previously linked browser window and have it load the new web page in Foreground
2
1349
by: andy.jones | last post by:
Hi I'm new to Javascript and wonder if anyone can give me some help? Im using document.documentElement.clientWidth to get the width of the users browser and it works fine so long as the users don't resize it. However, if the user re sizes it and then refreshes it , everthing is correct).
3
12213
by: =?Utf-8?B?KioqKiBLaXRlT3JlZ29uICoqKio=?= | last post by:
I am displaying some dynamic data in a content page, how do i figure out the height and width of the browser in asp.net? I know i can write javascript on the client side to get the information, but i need this information on the server side. thanks. -- Just another lost developer.....
1
2219
by: Starance | last post by:
Well... I'm not sure if this can be fixed, I've tried many ways. But here goes; When you resize your browser window it seems to move my video & photo divs. I want them kept in line with the main div. please help. Yes, its for myspace profile. <div class="main"> <table style="width="800px"; height="1024px"; cellpadding="0"; cellspacing="0";background-color="1c1c1c";"> <tr><td valign="top"> <tr> <td colspan="10">
2
2068
by: chowdary0783 | last post by:
Hi every one, I working on an web application in which clicking a button opens another window which will be dynamically populated with some data. Amount of data cannot be decided. I just want to fit the window size to the content of the data. Any suggestiosn?? Thanks a lot.
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10722
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10348
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9500
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5919
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.