| View previous topic :: View next topic |
yancho Site Admin
Joined: 13 Nov 2007 Posts: 56 Location: Iklin
|
Posted: Fri Nov 23, 2007 9:46 am Post subject: Getting Screen Resolutions |
|
|
|
Guys,
I need to make a script that manages to display an image depending on the screen size!
So I need a make the image displayed depending on the width / height of the resolution.
It has to be a cookie so I keep using it during the whole session.
I found some help if I want to send the data via GET but I just want to either set cookie / POST method.
Thanks _________________
 |
|
| Back to top |
|
|
yancho Site Admin
Joined: 13 Nov 2007 Posts: 56 Location: Iklin
|
Posted: Fri Nov 23, 2007 11:50 am Post subject: |
|
|
|
This is the workaround I found .. however if u have a less stupid way I would appreciate it
| php: |
<?
session_start();
if(isset($HTTP_COOKIE_VARS["users_resolution"])) {
$screen_res = $HTTP_COOKIE_VARS["users_resolution"];
setcookie ("width",$HTTP_COOKIE_VARS["width"]);
setcookie ("height",$HTTP_COOKIE_VARS["height"]);
}
else //means cookie is not found set it using Javascript
{
?>
<script language="javascript">
<!--
writeCookie();
function writeCookie()
{
var today = new Date();
var the_date = new Date("December 31, 9999");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie1 = "width="+ screen.width;
var the_cookie2 = "height="+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
var the_cookie1 = the_cookie1 + ";expires=" + the_cookie_date;
var the_cookie2 = the_cookie2 + ";expires=" + the_cookie_date;
document.cookie=the_cookie;
document.cookie=the_cookie1;
document.cookie=the_cookie2;
}
//-->
</script>
<?
}
print_r($_COOKIE);
echo "$screen_res";
?> |
_________________
 |
|
| Back to top |
|
|
hex4
Joined: 13 Nov 2007 Posts: 21 Location: Qormi, Malta
|
Posted: Fri Nov 23, 2007 4:13 pm Post subject: |
|
|
|
i dont think thats a stupid way :p
it's frequently to use javascript between php code
same goes for HTML  _________________ orlandev.com |
|
| Back to top |
|
|
killfr0g
Joined: 13 Nov 2007 Posts: 4 Location: Malta
|
Posted: Mon Nov 26, 2007 5:25 pm Post subject: |
|
|
|
| That looks OK but remember JavaScript or cookies may be turned off so it's not 100% reliable. Maybe you can do it using html and css, percentage based.. |
|
| Back to top |
|
|
Christian Sciberras
Joined: 11 Jan 2008 Posts: 8 Location: Malta
|
Posted: Mon Feb 11, 2008 6:09 pm Post subject: |
|
|
|
I agree with killfr0g, percentages should work better.
To do that just use some javascript which changes the image width/height dynamically.
But I suggest using some way to find the best resolution, so that whatever the percentages are, the image still displays nicely.
Or, use some div and span tags to hide some parts of the image, as if it were a java applet but with javascript. You could do that by setting the image as the background and setting the left/top coordinates with javascript.
Whatver the way, good luck! |
|
| Back to top |
|
|
varactor
Joined: 22 Dec 2008 Posts: 10 Location: Malta
|
Posted: Mon Dec 22, 2008 2:00 pm Post subject: |
|
|
|
CSS and HTML is the way to go.
That method ( javascript+ cookies etc ) is good when you need to make calculations based on the users resolution, such as processing some images using GD Library and returning them back to the user.
Also, most of you might know it but I would recommend having a look @ cross-browser dot com
There are loads of very good Screen Resolution functions.
Also, there is a good framework for PHP/JS, called xajax. Take a look at it, its not another yet common ajax library... |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group |
|
|