Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

User Display Size

16 views
Skip to first unread message

Summer

unread,
Sep 11, 2006, 9:08:31 PM9/11/06
to
I want to display an image that will adjust it's size based on the
size of the users window. Is this possible?


in...@swadd.nl

unread,
Sep 14, 2006, 3:01:14 PM9/14/06
to
Hello Summer

Try this with javascript That is probably the most elegant option. Most
likely the only option.

When jou start with a php indexpage you could do something like this.

Possible index.php

<?php
session_start();

if(isset($_POST['screenwidth'])){
// store screenwidth in a session
$_SESSION['screenwidth'] = $_POST['screenwidth'];
}
if(isset($_POST['screenheight'])){
// store screenheight in a session
$_SESSION['screenheight'] = $_POST['screenheight'];
}

// determine if screenwidth and heigth is already know. If not do this
if(!isset($_SESSION['screenwidth']) || !isset($_SESSION['screenheight'])){
?>
// simple page for processing javascript to determine screendimensions

<html>
<head>
<title>Welcome</title>

//simple script script
<script language=javascript1.2>
function detectUserScreen(){

/*determine width*/
screenWidth = screen.width;
/*determine height*/
screenHeight = screen.height;

/* Place values in form */
document.form1.screenwidth.value = screenWidth;
document.form1.screenheight.value = screenHeight;

/* Submit form tot index.php*/
document.form1.submit();
}
</script>

</head>
<body onLoad="javascript:detectUserScreen();">

<!-- simpel form to contain width and height-->
<form name="form1" action="index.php" method="POST">
<input type="hidden" name="screenwidth" value="">
<input type="hidden" name="screenheight" value="">
</form>

<!--nice message to user if server responds slow-->
<p>Wait for just a second. Page is loading.</p>
</body>
</html>
<?
}
// if width and height are known do this
else{
// do something else e.g. go to next page
header("location: index1.php");
}
?>

Save the code as index.php and run it.

Call your previous index.php index1.php and jour in business.

Screenwidth and height are stored in a session till user closes window or
you do session_destroy();

Hope this helps

Jerry

"Summer" <no...@nospam.xspam> schreef in bericht
news:122cg21mpem1nbspg...@4ax.com...

Summer

unread,
Sep 23, 2006, 12:40:19 AM9/23/06
to
Thanks Jerry. I know almost nothing about php and even less about
java. However, on the surface your code looks like it will work. One
more question if you don't mind. How do I access the height and width
values?

Mr-t

unread,
Sep 24, 2006, 3:47:42 AM9/24/06
to
I do something simular, but I use a cookie...

on the splash-screen of th website, the size is of no importance, but
once you visited that page, the rest of the site uses the cookie.

That approach doesn't need a form/user action.

0 new messages