By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,846 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,846 IT Pros & Developers. It's quick & easy.

Screen resolution

P: n/a
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 stylesheet switcher as part of the onload event but I would
rather link in the correct stylesheet for the resolution in the first
place.

Is there anyway of reading the screen resolution using PHP?

Please don't flame me about "screen resolution being useless as not
everyone browses in a maximised window". This is for intranet
application where I know the browser will be IE6 with javascript enabled
running in full screen mode and toolbars hidden. I also know the three
possible screen resolutions that it could be.
--
Steve Wright
Oct 16 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
>Please don't flame me about "screen resolution being useless as not
>everyone browses in a maximised window". This is for intranet
application where I know the browser will be IE6 with javascript enabled
running in full screen mode and toolbars hidden. I also know the three
possible screen resolutions that it could be.
Use code to translate the IP address of the workstation into the screen
resolution. Granted, this may require some manual collecting of data first.
Oct 16 '06 #2

P: n/a
On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
<us****@wrightnet.demon.co.uk>
<4R**************@wrightnet.demon.co.ukwrote:
>| 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 stylesheet switcher as part of the onload event but I would
| rather link in the correct stylesheet for the resolution in the first
| place.
|
| Is there anyway of reading the screen resolution using PHP?
Not really.
>| Please don't flame me about "screen resolution being useless as not
| everyone browses in a maximised window". This is for intranet
| application where I know the browser will be IE6 with javascript enabled
| running in full screen mode and toolbars hidden. I also know the three
| possible screen resolutions that it could be.
Let the browser do the work (like it should) and let the user select
what option that they want.
-------------------------------------------------------------------
<head>
<link rel="stylesheet" type="text/css" href="small.css" title="small"
/>
<link rel="alternate stylesheet" type="text/css" href="medium.css"
title="medium" />
<link rel="alternate stylesheet" type="text/css" href="large.css"
title="large" />

<script type="text/javascript">
function setActiveStyleSheet(title)
{
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 &&
a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
</head>
<body>
<p><strong>Screen Size</strong><br />
<select name="lbCSS" id="lbCSS"
onchange="setActiveStyleSheet(this.value);">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
</body>
----------------------------------------------------------------------
If you want the appropriate css to be loaded each time then store the
value in a cookie and read/update this value.

ALternatively, you could use CSS floating layout. This will allow the
browser to automatically resize it's contents. You only need 1 CSS
file to manage the myriad of screen resolutions that are available.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 17 '06 #3

P: n/a
Steve Wright wrote:
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 stylesheet switcher as part of the onload event but I would
rather link in the correct stylesheet for the resolution in the first
place.

Is there anyway of reading the screen resolution using PHP?
Nope. The use of document.write (circa 1990s) will work just as well
though.

<script>

var css = 'norm.css';

if(screen.availHeight 1024) {
css = 'big.css';
}
/* ... etc. ... */

document.write('<link rel="stylesheet" type="text/css" href="' + css +
'">');

</script>

Oct 17 '06 #4

P: n/a
In message <12*************@corp.supernews.com>, Gordon Burditt
<go***********@burditt.orgwrites
>>Please don't flame me about "screen resolution being useless as not
everyone browses in a maximised window". This is for intranet
application where I know the browser will be IE6 with javascript enabled
running in full screen mode and toolbars hidden. I also know the three
possible screen resolutions that it could be.

Use code to translate the IP address of the workstation into the screen
resolution. Granted, this may require some manual collecting of data first.

Interesting idea, but we have dynamic IP addresses.
--
Steve Wright
Oct 17 '06 #5

P: n/a
In message <cg********************************@4ax.com>, Jeff North
<jn******@yahoo.com.auwrites
>On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
<us****@wrightnet.demon.co.uk>
<4R**************@wrightnet.demon.co.ukwrote:
>>| 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 stylesheet switcher as part of the onload event but I would
| rather link in the correct stylesheet for the resolution in the first
| place.
|
| Is there anyway of reading the screen resolution using PHP?

Not really.
>>| Please don't flame me about "screen resolution being useless as not
| everyone browses in a maximised window". This is for intranet
| application where I know the browser will be IE6 with javascript enabled
| running in full screen mode and toolbars hidden. I also know the three
| possible screen resolutions that it could be.

Let the browser do the work (like it should) and let the user select
what option that they want.
-------------------------------------------------------------------
<head>
<link rel="stylesheet" type="text/css" href="small.css" title="small"
/>
<link rel="alternate stylesheet" type="text/css" href="medium.css"
title="medium" />
<link rel="alternate stylesheet" type="text/css" href="large.css"
title="large" />

<script type="text/javascript">
function setActiveStyleSheet(title)
{
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 &&
a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
</head>
<body>
<p><strong>Screen Size</strong><br />
<select name="lbCSS" id="lbCSS"
onchange="setActiveStyleSheet(this.value);">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
</select>
</body>
----------------------------------------------------------------------
If you want the appropriate css to be loaded each time then store the
value in a cookie and read/update this value.

ALternatively, you could use CSS floating layout. This will allow the
browser to automatically resize it's contents. You only need 1 CSS
file to manage the myriad of screen resolutions that are available.
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
That's the fall back option I thought of. However its not just the text
I'm scaling, its the graphics as well. I'm using PHP and the GD
extension to generate the six images. These images consume most of the
space on the screen hence the need to scale them correctly.
--
Steve Wright
Oct 17 '06 #6

P: n/a
On Tue, 17 Oct 2006 08:51:08 +0100, in comp.lang.php Steve Wright
<us****@wrightnet.demon.co.uk>
<Kb**************@wrightnet.demon.co.ukwrote:
>| In message <cg********************************@4ax.com>, Jeff North
| <jn******@yahoo.com.auwrites
| >On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
| ><us****@wrightnet.demon.co.uk>
| ><4R**************@wrightnet.demon.co.ukwrote:
| >
| >>| 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 stylesheet switcher as part of the onload event but I would
| >>| rather link in the correct stylesheet for the resolution in the first
| >>| place.
| >>|
| >>| Is there anyway of reading the screen resolution using PHP?
| >
| >Not really.
| >
| >>| Please don't flame me about "screen resolution being useless as not
| >>| everyone browses in a maximised window". This is for intranet
| >>| application where I know the browser will be IE6 with javascript enabled
| >>| running in full screen mode and toolbars hidden. I also know the three
| >>| possible screen resolutions that it could be.
| >
| >Let the browser do the work (like it should) and let the user select
| >what option that they want.
| >-------------------------------------------------------------------
| ><head>
| ><link rel="stylesheet" type="text/css" href="small.css" title="small"
| >/>
| ><link rel="alternate stylesheet" type="text/css" href="medium.css"
| >title="medium" />
| ><link rel="alternate stylesheet" type="text/css" href="large.css"
| >title="large" />
| >
| ><script type="text/javascript">
| >function setActiveStyleSheet(title)
| >{
| var i, a, main;
| for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
| if(a.getAttribute("rel").indexOf("style") != -1 &&
| >a.getAttribute("title")) {
| a.disabled = true;
| if(a.getAttribute("title") == title) a.disabled = false;
| }
| }
| >}
| ></head>
| ><body>
| ><p><strong>Screen Size</strong><br />
| ><select name="lbCSS" id="lbCSS"
| >onchange="setActiveStyleSheet(this.value);">
| <option value="small">Small</option>
| <option value="medium">Medium</option>
| <option value="large">Large</option>
| ></select>
| ></body>
| >----------------------------------------------------------------------
| >If you want the appropriate css to be loaded each time then store the
| >value in a cookie and read/update this value.
| >
| >ALternatively, you could use CSS floating layout. This will allow the
| >browser to automatically resize it's contents. You only need 1 CSS
| >file to manage the myriad of screen resolutions that are available.
|
| That's the fall back option I thought of. However its not just the text
| I'm scaling, its the graphics as well. I'm using PHP and the GD
| extension to generate the six images. These images consume most of the
| space on the screen hence the need to scale them correctly.
Use percentages on the width/height.
<img src="xyz.gif" width="100%" height="75%" />
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 17 '06 #7

P: n/a
Why not JavaScript AND PHP:

at the very top of the page, put:
<?php
if( !isset($_GET['x']) || !isset($_GET['y']) ) {
echo '<script type="text/javascript">';
echo 'window.location="THIS_PAGE.php?x=" + screen.availWidth + "&y="
+ screen.availHeight';
echo '</script>';
die();
}

// now write the rest of your page, with $_GET['x'] and $_GET['y'] as
the resolution.

?>

this code will refresh the page instantly with the screen width &
height.


Jeff North wrote:
On Tue, 17 Oct 2006 08:51:08 +0100, in comp.lang.php Steve Wright
<us****@wrightnet.demon.co.uk>
<Kb**************@wrightnet.demon.co.ukwrote:
| In message <cg********************************@4ax.com>, Jeff North
| <jn******@yahoo.com.auwrites
| >On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
| ><us****@wrightnet.demon.co.uk>
| ><4R**************@wrightnet.demon.co.ukwrote:
| >
| >>| 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 stylesheet switcher as part of the onload event but I would
| >>| rather link in the correct stylesheet for the resolution in the first
| >>| place.
| >>|
| >>| Is there anyway of reading the screen resolution using PHP?
| >
| >Not really.
| >
| >>| Please don't flame me about "screen resolution being useless as not
| >>| everyone browses in a maximised window". This is for intranet
| >>| application where I know the browser will be IE6 with javascript enabled
| >>| running in full screen mode and toolbars hidden. I also know the three
| >>| possible screen resolutions that it could be.
| >
| >Let the browser do the work (like it should) and let the user select
| >what option that they want.
| >-------------------------------------------------------------------
| ><head>
| ><link rel="stylesheet" type="text/css" href="small.css" title="small"
| >/>
| ><link rel="alternate stylesheet" type="text/css" href="medium.css"
| >title="medium" />
| ><link rel="alternate stylesheet" type="text/css" href="large.css"
| >title="large" />
| >
| ><script type="text/javascript">
| >function setActiveStyleSheet(title)
| >{
| var i, a, main;
| for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
| if(a.getAttribute("rel").indexOf("style") != -1 &&
| >a.getAttribute("title")) {
| a.disabled = true;
| if(a.getAttribute("title") == title) a.disabled = false;
| }
| }
| >}
| ></head>
| ><body>
| ><p><strong>Screen Size</strong><br />
| ><select name="lbCSS" id="lbCSS"
| >onchange="setActiveStyleSheet(this.value);">
| <option value="small">Small</option>
| <option value="medium">Medium</option>
| <option value="large">Large</option>
| ></select>
| ></body>
| >----------------------------------------------------------------------
| >If you want the appropriate css to be loaded each time then store the
| >value in a cookie and read/update this value.
| >
| >ALternatively, you could use CSS floating layout. This will allow the
| >browser to automatically resize it's contents. You only need 1 CSS
| >file to manage the myriad of screen resolutions that are available.
|
| That's the fall back option I thought of. However its not just the text
| I'm scaling, its the graphics as well. I'm using PHP and the GD
| extension to generate the six images. These images consume most of the
| space on the screen hence the need to scale them correctly.

Use percentages on the width/height.
<img src="xyz.gif" width="100%" height="75%" />
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 17 '06 #8

P: n/a
On 17 Oct 2006 11:03:20 -0700, in comp.lang.php "maven22"
<ma**********@gmail.com>
<11*********************@f16g2000cwb.googlegroups. comwrote:
>| Jeff North wrote:
| On Tue, 17 Oct 2006 08:51:08 +0100, in comp.lang.php Steve Wright
| <us****@wrightnet.demon.co.uk>
| <Kb**************@wrightnet.demon.co.ukwrote:
| >
| | In message <cg********************************@4ax.com>, Jeff North
| | <jn******@yahoo.com.auwrites
| | >On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
| | ><us****@wrightnet.demon.co.uk>
| | ><4R**************@wrightnet.demon.co.ukwrote:
| | >
| | >>| 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 stylesheet switcher as part of the onload event but I would
| | >>| rather link in the correct stylesheet for the resolution in the first
| | >>| place.
| | >>|
| | >>| Is there anyway of reading the screen resolution using PHP?
| | >
| | >Not really.
| | >
| | >>| Please don't flame me about "screen resolution being useless as not
| | >>| everyone browses in a maximised window". This is for intranet
| | >>| application where I know the browser will be IE6 with javascript enabled
| | >>| running in full screen mode and toolbars hidden. I also know the three
| | >>| possible screen resolutions that it could be.
| | >
| | >Let the browser do the work (like it should) and let the user select
| | >what option that they want.
| | >-------------------------------------------------------------------
| | ><head>
| | ><link rel="stylesheet" type="text/css" href="small.css" title="small"
| | >/>
| | ><link rel="alternate stylesheet" type="text/css" href="medium.css"
| | >title="medium" />
| | ><link rel="alternate stylesheet" type="text/css" href="large.css"
| | >title="large" />
| | >
| | ><script type="text/javascript">
| | >function setActiveStyleSheet(title)
| | >{
| | var i, a, main;
| | for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
| | if(a.getAttribute("rel").indexOf("style") != -1 &&
| | >a.getAttribute("title")) {
| | a.disabled = true;
| | if(a.getAttribute("title") == title) a.disabled = false;
| | }
| | }
| | >}
| | ></head>
| | ><body>
| | ><p><strong>Screen Size</strong><br />
| | ><select name="lbCSS" id="lbCSS"
| | >onchange="setActiveStyleSheet(this.value);">
| | <option value="small">Small</option>
| | <option value="medium">Medium</option>
| | <option value="large">Large</option>
| | ></select>
| | ></body>
| | >----------------------------------------------------------------------
| | >If you want the appropriate css to be loaded each time then store the
| | >value in a cookie and read/update this value.
| | >
| | >ALternatively, you could use CSS floating layout. This will allow the
| | >browser to automatically resize it's contents. You only need 1 CSS
| | >file to manage the myriad of screen resolutions that are available.
| |
| | That's the fall back option I thought of. However its not just the text
| | I'm scaling, its the graphics as well. I'm using PHP and the GD
| | extension to generate the six images. These images consume most of the
| | space on the screen hence the need to scale them correctly.
| >
| Use percentages on the width/height.
| <img src="xyz.gif" width="100%" height="75%" />
|
| Why not JavaScript AND PHP:
|
| at the very top of the page, put:
| <?php
| if( !isset($_GET['x']) || !isset($_GET['y']) ) {
| echo '<script type="text/javascript">';
| echo 'window.location="THIS_PAGE.php?x=" + screen.availWidth + "&y="
| + screen.availHeight';
| echo '</script>';
| die();
| }
|
| // now write the rest of your page, with $_GET['x'] and $_GET['y'] as
| the resolution.
|
| ?>
|
| this code will refresh the page instantly with the screen width &
| height.
Well there's no right way or wrong way, IMNSHO.

The problem I see with your code is that you are assuming that the
person has their browser open full screen, this may or maynot be the
case.

Not all browsers implement clientWidth/Height so your code would need
some additional 'sniffing' to work out the values (not to mention that
the data is passed in the url and therefore you'd need to error
detection on these value i.e. index.php?x=apples&y=oranges).
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 18 '06 #9

P: n/a
Of course I didn't include error detection because it's just for
concept - I'm not writing his code for him. And, he stated this at the
beginning "This is for intranet
application where I know the browser will be IE6 with javascript
enabled
running in full screen mode and toolbars hidden"
Jeff North wrote:
On 17 Oct 2006 11:03:20 -0700, in comp.lang.php "maven22"
<ma**********@gmail.com>
<11*********************@f16g2000cwb.googlegroups. comwrote:
| Jeff North wrote:
| On Tue, 17 Oct 2006 08:51:08 +0100, in comp.lang.php Steve Wright
| <us****@wrightnet.demon.co.uk>
| <Kb**************@wrightnet.demon.co.ukwrote:
| >
| | In message <cg********************************@4ax.com>, Jeff North
| | <jn******@yahoo.com.auwrites
| | >On Mon, 16 Oct 2006 23:50:50 +0100, in comp.lang.php Steve Wright
| | ><us****@wrightnet.demon.co.uk>
| | ><4R**************@wrightnet.demon.co.ukwrote:
| | >
| | >>| 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 stylesheet switcher as part of the onload event but I would
| | >>| rather link in the correct stylesheet for the resolution in the first
| | >>| place.
| | >>|
| | >>| Is there anyway of reading the screen resolution using PHP?
| | >
| | >Not really.
| | >
| | >>| Please don't flame me about "screen resolution being useless as not
| | >>| everyone browses in a maximised window". This is for intranet
| | >>| application where I know the browser will be IE6 with javascript enabled
| | >>| running in full screen mode and toolbars hidden. I also know the three
| | >>| possible screen resolutions that it could be.
| | >
| | >Let the browser do the work (like it should) and let the user select
| | >what option that they want.
| | >-------------------------------------------------------------------
| | ><head>
| | ><link rel="stylesheet" type="text/css" href="small.css" title="small"
| | >/>
| | ><link rel="alternate stylesheet" type="text/css" href="medium.css"
| | >title="medium" />
| | ><link rel="alternate stylesheet" type="text/css" href="large.css"
| | >title="large" />
| | >
| | ><script type="text/javascript">
| | >function setActiveStyleSheet(title)
| | >{
| | var i, a, main;
| | for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
| | if(a.getAttribute("rel").indexOf("style") != -1 &&
| | >a.getAttribute("title")) {
| | a.disabled = true;
| | if(a.getAttribute("title") == title) a.disabled = false;
| | }
| | }
| | >}
| | ></head>
| | ><body>
| | ><p><strong>Screen Size</strong><br />
| | ><select name="lbCSS" id="lbCSS"
| | >onchange="setActiveStyleSheet(this.value);">
| | <option value="small">Small</option>
| | <option value="medium">Medium</option>
| | <option value="large">Large</option>
| | ></select>
| | ></body>
| | >----------------------------------------------------------------------
| | >If you want the appropriate css to be loaded each time then store the
| | >value in a cookie and read/update this value.
| | >
| | >ALternatively, you could use CSS floating layout. This will allow the
| | >browser to automatically resize it's contents. You only need 1 CSS
| | >file to manage the myriad of screen resolutions that are available.
| |
| | That's the fall back option I thought of. However its not just the text
| | I'm scaling, its the graphics as well. I'm using PHP and the GD
| | extension to generate the six images. These images consume most of the
| | space on the screen hence the need to scale them correctly.
| >
| Use percentages on the width/height.
| <img src="xyz.gif" width="100%" height="75%" />
|
| Why not JavaScript AND PHP:
|
| at the very top of the page, put:
| <?php
| if( !isset($_GET['x']) || !isset($_GET['y']) ) {
| echo '<script type="text/javascript">';
| echo 'window.location="THIS_PAGE.php?x=" + screen.availWidth + "&y="
| + screen.availHeight';
| echo '</script>';
| die();
| }
|
| // now write the rest of your page, with $_GET['x'] and $_GET['y'] as
| the resolution.
|
| ?>
|
| this code will refresh the page instantly with the screen width &
| height.

Well there's no right way or wrong way, IMNSHO.

The problem I see with your code is that you are assuming that the
person has their browser open full screen, this may or maynot be the
case.

Not all browsers implement clientWidth/Height so your code would need
some additional 'sniffing' to work out the values (not to mention that
the data is passed in the url and therefore you'd need to error
detection on these value i.e. index.php?x=apples&y=oranges).
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Oct 18 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.