How to determine screen size?

Posted by adisney on 04-Aug-2011 19:25

We're writing an application which displays a doctor's schedule to a browser - can be accessed on anything from a laptop to an iPhone.

We have a couple of different logos to show, depending on the screen size, so that if the doctor is using his/her phone, the screen is not filled up with something useless in that environment.

We have a little java function which we use to display various bits of information at the bottom of each page:

<script type="text/javascript">
   var environmentInfo =
      navigator.appCodeName + ", " + navigator.appName + ", " +
      navigator.platform    + ", " + screen.width + "x" + screen.height;

   document.getElementById("environmentInfo").innerHTML=environmentInfo;
</script>

Displays in very tiny gray text something like: Mozilla, Microsoft Internet Explorer, Win32, 1152x864

This works well, but what we need to do is to get environmentInfo (well, a much simpler version of it containing just screen.width) into a Progress variable, so we can look up in the database the correct logo to show, based on the doctor's practice and the screen size.

Does anyone know how?   It's probably perfectly obvious (sigh)

Message was edited by: Anne Disney

All Replies

Posted by Admin on 04-Aug-2011 23:11

This works well, but what we need to do is to get environmentInfo (well, a much simpler version of it containing just screen.width) into a Progress variable, so we can look up in the database the correct logo to show, based on the doctor's practice and the screen size.

 

You'll have to send the value to the server using either and URL parameter or a hidden field in a form. For the URL parameter, the first page the browser ever hits, should forward it to another page:

Use the onLoad of the body tag/java script event with somewhile like this:

onLoad = 'window.location=nextPage.html?width=" + screen.width + "&height=" + screen.height;'

In nextPage.html (or nextPage.w depending on your way of WebSpeed coding) you can use

get-value ("width") and get-value ("height").

(I coded this in outlook and didn't test it, so there might be minor issues with the code).

Posted by adisney on 05-Aug-2011 12:34

Thanks, Mike.

This thread is closed