473,549 Members | 2,592 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 5621
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
2098
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
19906
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
8882
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
1832
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"...
33
4038
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...
2
1333
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
12201
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
2202
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";...
2
2053
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
7527
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7819
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...
0
6052
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...
1
5377
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...
0
5097
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...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.