Mobile Detection using Javascript
Posted: Wed Jun 01, 2011 1:15 am
First I'd like to thank you for developing Tera Wurfl. Great!
Now to the problem. Even though I did some C programming in the 80's I realize those skills are nearly dead after years of neglect.
The PHP exampes I found on tera-wurfl.com was quite similar to what I wanted to achieve so I managed however quite easily to get the PHP remote client to detect and redirect mobile users using the code below.
This seems to work just fine after some basic testing so I'm very happy about that.
Now I try to do the same with the Javascript Remote Client but I don't know how to get it working even though I look at the example that comes with tera-wurfl.
Can someone give some hints how how the code would look like?
Another thing I solved but had some initial problem with during the Tera-Wurfl installation was loading the XML file to the database. I had to change so the simpleXML parser was used as the preferred parser, otherwise I got an out of memory error. I use Hostgator and noticed someone else had a similar problem/solution with Hostgator.
Cheers
Peter
Now to the problem. Even though I did some C programming in the 80's I realize those skills are nearly dead after years of neglect.
The PHP exampes I found on tera-wurfl.com was quite similar to what I wanted to achieve so I managed however quite easily to get the PHP remote client to detect and redirect mobile users using the code below.
- Code: Select all
<?php
require_once ('TeraWurflRemoteClient.php');
$wurflObj = new TeraWurflRemoteClient('http://MyTeraWurflMainDomain.com/tera-wurfl/webservice.php');
$capabilities = array("is_wireless_device");
$wurflObj->getCapabilitiesFromAgent(TeraWurflRemoteClient::getUserAgent(),$capabilities);
if($wurflObj->getDeviceCapability("is_wireless_device")){
header("Location: http://myMobileDomain.mobi/");}
?>
This seems to work just fine after some basic testing so I'm very happy about that.
Now I try to do the same with the Javascript Remote Client but I don't know how to get it working even though I look at the example that comes with tera-wurfl.
Can someone give some hints how how the code would look like?
Another thing I solved but had some initial problem with during the Tera-Wurfl installation was loading the XML file to the database. I had to change so the simpleXML parser was used as the preferred parser, otherwise I got an out of memory error. I use Hostgator and noticed someone else had a similar problem/solution with Hostgator.
Cheers
Peter