Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-04-2006, 11:49 AM   PM User | #1
Crowds
Regular Coder

 
Join Date: May 2005
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Crowds is an unknown quantity at this point
Browser Res Detection and Includes....

I know that being server side, php cannot detect screen res. But I am wondering If I could use Javascript to detect the screen res and then use PHP to load the appropriate include ().
What I have is a site that ports well between different resolutions apart from its header (which contains the main nav and search input box) which hangs off the right hand side. As the header is an include I figure that I could make two versions of this include. And load the appropriate one depending on a screen width varible say < 1024 or > 1024.

Would you say this is possible ?

Crowds
__________________
PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design
Crowds is offline   Reply With Quote
Old 05-04-2006, 02:23 PM   PM User | #2
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
You can use Javascript to detect the resolution (secreenwidth) and then add it to a querystring or hidden form variable.
Submit this and PHP can then grab the variable.

It's rare these days for people to have different pages for screen res.
You can use PHP with Dynamic Style sheets to change the look of a site.
degsy is offline   Reply With Quote
Old 05-04-2006, 03:33 PM   PM User | #3
Crowds
Regular Coder

 
Join Date: May 2005
Posts: 235
Thanks: 0
Thanked 0 Times in 0 Posts
Crowds is an unknown quantity at this point
Thanks degsys,
In most circumstances I would css to create a 'liquid' header but it is not practical in this case. And I am loath to create two seperate sites (one 800 and another 1024) when it is just the header that is broken under 800x600.

Ok before I query the php side further
Would this javascript establish the variables before PHP grabs it ?

Code:
<script language='Javascript'>
<!--
if (screen.width <= 800){var sr = "800";}
else if (screen.width <= 1024){var sr = "1024";}
//-->
</script>
Cheers

Crowds
__________________
PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design
Crowds is offline   Reply With Quote
Old 05-04-2006, 06:47 PM   PM User | #4
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Try to remember that not everyone has their browser windows maximised, so detecting the screen res isn't really going to help.
You need to detect the viewport dimensions.

http://www.codingforums.com/showthre...199#post429199
Bill Posters is offline   Reply With Quote
Old 05-04-2006, 09:37 PM   PM User | #5
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
Huh? The screen cannot be maximized/minimized.
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
marek_mar is offline   Reply With Quote
Old 05-04-2006, 10:52 PM   PM User | #6
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
You can't change the window size someone is using to view your page. If they want to only use 1/4 of their screen for the browser because they are doing other things in the rest of the screen then that is THEIR choice. Most browsers will only allow you to resize a window that you open (unless the browser owner has disabled the function so that you can't resize at all).

Even if you could maximise - any fixed toolbars they have on the screen will reduce the available space for the browser plus different browsers use different amounts of space for their own toolbars etc.

Code:
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 05-05-2006, 03:06 PM   PM User | #7
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
Quote:
You can't change the window size someone is using to view your page. If they want to only use 1/4 of their screen for the browser because they are doing other things in the rest of the screen then that is THEIR choice
You can change the size, position and fullscreen state of a window. You cannot change the toolbar properties unless it is a popup.



Quote:
Would this javascript establish the variables before PHP grabs it ?
You have to pass it to PHP. You either do this by putting those javascript variables into a querystring then loading the page using location or you put them into hidden formvariables and submit the form.
degsy is offline   Reply With Quote
Old 05-05-2006, 03:17 PM   PM User | #8
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Quote:
Originally Posted by degsy
You can change the size, position and fullscreen state of a window. You cannot change the toolbar properties unless it is a popup.
What you mean is - you can try.
With many browsers now natively offering users a way to prevent this kind of manipulation, the attempt isn't always going to be successful.
For that matter, the attempt isn't always going to be welcomed by users, hence the addition of moveTo/resizeTo blockers by popular request.

Quote:
You have to pass it to PHP. You either do this by putting those javascript variables into a querystring then loading the page using location or you put them into hidden formvariables and submit the form.
You could also 'bounce' the value from js to PHP using cookies.
i.e. write the cookie with js and follow up by reading the cookie with PHP.
(of course, dependent on the user accepting cookies.)
Bill Posters is offline   Reply With Quote
Old 05-05-2006, 03:20 PM   PM User | #9
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
Quote:
What you mean is - you can try.
You can say that about any javascript.
degsy is offline   Reply With Quote
Old 05-05-2006, 03:26 PM   PM User | #10
Bill Posters
Senior Coder

 
Join Date: Feb 2003
Posts: 1,665
Thanks: 0
Thanked 27 Times in 25 Posts
Bill Posters will become famous soon enough
Indeed. I'm frequently reminding people that they can't always rely on js-dependent techniques to work, if I think it isn't already clear to them.
I considered the point needed making here, particularly as you can't even rely on the technique working for all those users who actually have js-enabled UAs.
Bill Posters is offline   Reply With Quote
Old 05-05-2006, 03:31 PM   PM User | #11
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
Considering that PHP cannot detect the screen properties then there isn't much choice if that's what he wants to do.

I don't agree with the method i'm just mentioning the various solutions.
degsy is offline   Reply With Quote
Old 05-05-2006, 11:41 PM   PM User | #12
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Since it is easy to turn off the ability of javascript to resize any window so that browser windows display the size that you want them at and not be dictated to by the author of a web page the best way of handling the situation is to check the actual space available in the window rather than the screen resolution (which tells you nothing about how high or wide the available area is even for a maximized window since you have to subtract for any fixed toolbard and the browser chrome - all of which can vary significantly).

If I were to place toolbars down the right side of my screen that take up 100 pixels of the screen width then a maximized browser window will be 100 pixels narrower than you would expect from looking at screen.width because the browser will not overlap the toolbars. Admittedly most people put the toolbars at the bottom of the screen but nothing says anything about where they have to be so you can move them if you want to.

The only time capturing screen.width is at all useful is if you want it for statistical purposes (x% of javascript enabled visitors use a certain resolution).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:41 AM.


Advertisement
Log in to turn off these ads.