PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

browser resolution

maybe not on topic but it's the best place I've found to ask this :)

how can I detect that my web page is being accessed from a pocket pc or smartphone device? I've been looking at pocket explorer and I get an "UA-pixels" header which tells me the browser resolution, but can I rely on that? Is opera giving me the resolution too? Is there any safest option?

TIA
Kak
What's wrong with checking the User-Agent?
sponge wrote:What's wrong with checking the User-Agent?


I'm not sure as it's the first time I do this kind of thing, but I think there are hundreds of user agent strings... it's just a matter of choosing which agents come from a pocket device?
Yes, generally it's just Pocket IE or Netfront.
sponge wrote:Yes, generally it's just Pocket IE or Netfront.


ok, lots of thanks, I'll try with those strings for the moment :)
This is what we use at PocketGamer (copied and pasted from an email to someone else).

There are two ways to redirect automatically - the first with PHP:
Code:

<?

if (stristr($ua, "Windows CE") or stristr($ua, "AvantGo") or stristr($ua,
"Mazingo") or stristr($ua, "Mobile ") or stristr($ua, "T68") or stristr($ua,
"Syncalot") or stristr($ua, "Blazer") )
{
$DEVICE_TYPE="MOBILE";
}

if (isset($DEVICE_TYPE) and $DEVICE_TYPE=="MOBILE ")
{
$location='mobile/index.php';
header ('Location: '.$location);
exit;
}

?>

The other is with Javascript:

<pre><script>
var isCE = navigator.appVersion.indexOf("Windows CE")>0;
if (isCE)
{
window.location.href="mobile/";
}
</script></pre>

As the PHP code involves headers, it's essential that it goes before any other header() calls. I imagine the Javascript could go anywhere, but it'll look pretty dopey if the page renders and then redirects. ;-)