473,386 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

resolution css redirect script

Hi Guys

The script below works perfectly in Mozilla, but not in IE... any
ideas?
It specifies a specific style sheet for 3 types of resolutions.

---------------------------------------------------------------------------

var myWidth = 0;

if( typeof(window.innerWidth) == 'number' ) {
myWidth = window.innerWidth;
}else if(typeof(document.documentElement.clientWidth) == 'number'){
myWidth = document.documentElement.clientWidth;
}else if(typeof(document.body.clientWidth) == 'number'){
myWidth = document.body.clientWidth;
}

if (myWidth <= 1280) {
document.write('<link rel="stylesheet" type="text/css"
href="about_1280.css">');
}
if (myWidth <= 1024) {
document.write('<link rel="stylesheet" type="text/css"
href="about_1024.css">');
}
if (myWidth <= 800) {
document.write('<link rel="stylesheet" type="text/css"
href="about_800.css">');
}

------------------------------------------------------------------------

Thanks
K

Aug 2 '06 #1
2 2751
ko******@gmail.com wrote:
The script below works perfectly in Mozilla, but not in IE... any
ideas?
<snip>
}else if(typeof(document.documentElement.clientWidth) == 'number'){
myWidth = document.documentElement.clientWidth;
}else if(typeof(document.body.clientWidth) == 'number'){
myWidth = document.body.clientWidth;
}
<snip>

The decision as to which of documentElement.clientWidth and
body.clientWidth holds the actual width of the client-region of the
window depends on the 'mode' (as may be read from - document.compatMode
-) of the document. In 'CSS1Compat' mode the documentElement is the
object to look at, while in 'BackCompat' mode it is the body. From IE5
on both properties are defined and have numeric type (and on IE < 5
attempting to execute - document.documentElement.clientWidth - will
error as no - documentElement - property of the document is available).

If your document is in 'BackCompat' mode on IE your - myWidth - will be
set to zero.

Richard.

Aug 2 '06 #2
JRS: In article <11**********************@i42g2000cwa.googlegroups .com>
, dated Wed, 2 Aug 2006 05:19:13 remote, seen in
news:comp.lang.javascript, ko******@gmail.com posted :
>The script below works perfectly in Mozilla, but not in IE... any
ideas?
It specifies a specific style sheet for 3 types of resolutions.
Why does it specify no style sheet for the fourth type?

Your output could more compactly have been written as something like

document.write('<link rel="stylesheet" type="text/css" href="about_' +
( myWidth<=800 ? '800' : myWidth<=1024 ? '1024' :
myWidth<=1280 ? '1280' : '' ) + '.css">');

in which I have retained the bug.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 3 '06 #3

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

Similar topics

10
by: Bob Garbados | last post by:
forgive my ignorance, as I'm new to php coming from a ms background... If I create a page named redirect.php and it's only content is: <?php header("Location: http://www.google.com"); ?>...
2
by: Sentinel | last post by:
here is the entire thread From: "Kimmo Laine" <eternal.erectionN0.5P@Mgmail.com> Subject: Re: script in body Date: Mon, 20 Jun 2005 17:46:28 +0300 Message-ID:...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
10
by: Prophet | last post by:
when I first started to write my page, I had my settings at 1024 x 768. I then saw the page on a 800 x 600 computer - wow - what a difference!!! I then went back and redid my page at 800 x 600....
1
by: fabrice | last post by:
Hi, I'm trying to get the screen resolution of the client and to realize a treatment in code behind. it seem to be hard. I can get information about the resolution with this following sub,...
6
by: Sandy Pittendrigh | last post by:
I have a fishing related site with a billion photos, where 600 pixels as a maximum photo width looks OK at both low resolution and high resolution, but spectacular in neither. Browser stats sites...
0
by: bcobra | last post by:
What am I doing wrong? the code: age Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %> <%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"...
9
by: Steve Wright | last post by:
Hi I'm developing a webpage that needs to include a different stylesheet depending on the screen resolution. I know that I could read the resolution in javascript and then do some sort of...
2
by: one.1more | last post by:
Hello, I have the following code but its not working. i want my site to be accessible only if the visitors resolution is 1024 x 768 or higher and only if they are using internet explorer. the...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.