Click to See Complete Forum and Search --> : Do you know how to...


ryneaux
05-30-2003, 02:38 PM
Does anyone know how to find screen coordinates of an image?

Here's what I want to do...

I have a DHTML drop down menu, but it works off of absolute positioning. In this case, I would like to center it. In order to center it I need to know the visitors screen resolution, but my problem there is, what if the visitor doesn't have there browser open completely. So, I was thinking that if I can put an image in a table that would mark where the drop down should start I can use its position to set the absolute position of the drop down.

I just don't know how to do that or if it is possible.

Does anyone have any suggestions?

I would appreciate it.

Thanks,
Ryan

tsinka
05-30-2003, 04:06 PM
Hi,

can you post some code ? That makes it easier to find a solution :)

weekender
05-30-2003, 04:09 PM
using javascript, you can find the users window size - ie size of window, not screen. then use that to center.

or you could have a table 100% high and 100%wide - ie filling the window, with VALIGN=center and ALIGN=center - and put the image in that, so it's in the very center of the table.

ryneaux
05-30-2003, 06:35 PM
Hello and thank you for your replies.

I am now using a Java script to detect the width of the document. That is a good thing, but now my problem is how to get that value assigned to a variable in PHP.

here's the java script :


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showres() {
var myscreen = document.body.clientWidth;
document.write(myscreen);
}
// End -->
</script>


that is in the head, this is in the body :


<script language="javascript">showres();</script>

So, it prints out the width inside the browser window, but I need to assign that value to a PHP variable, and I haven't figured that out yet.

Again thank you for your responses.
Ryan

weekender
05-31-2003, 08:43 AM
you can't assign a php variable using javascript, and the reason is this;

javascript is client-side, php is server-side. This means that php is executed (parsed) by the server before it sends the output to the browser (client), and javascript is processed at the client. Therefore, js can only be parsed after php (time wise).

leatherback
05-31-2003, 08:54 AM
an addition to weekenders responce.

You could parse a var from javascript, but it requires a reload of the page.

You can call the page again after the javascript has run, setting a variable with the width.

(in your javascript something like: newLocation = "page.php?width=" + myscreen ")

You check in the php code for the var width, if it is not set, you only load a very small page (Basically just the javascript) after wich you reload the fullppage.

realize though the consequences if people have javascript disabled!!

J.