sazzie Posted February 16, 2007 Share Posted February 16, 2007 I have a php based xhtml webpage which is javascript heavy. Due to the javascript, this webpage will not load in my mobile phone browser. What I want to achieve is to use the same webpage but direct the mobile phone browser to a function in my php script which will provided beter suited output for a mobile browser. Also I would need differently designed scripts for explorer and firefox. Can someone please advise me on how to achieve this desire effect? Quote Link to comment Share on other sites More sharing options...
clarke78 Posted February 16, 2007 Share Posted February 16, 2007 I believe you can use CSS to send a simplified version of your webpage to the mobile phone. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 but are you wondering on how to detect if the browser is a mobile phone? Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 I believe you can use CSS to send a simplified version of your webpage to the mobile phone. Would you mind elaborating on that point, please ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 You use the media tag <link rel="stylesheet" type="text/css" href="/common.css" media="screen, print, projection, handheld" /> <link rel="stylesheet" type="text/css" href="/screen.css" media="screen, projection" /> <link rel="stylesheet" type="text/css" href="/print.css" media="print" /> <link rel="stylesheet" type="text/css" href="/handheld.css" media="handheld" /> Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 but are you wondering on how to detect if the browser is a mobile phone? Exactly right! If I can detect what kind of browser is connecting I can choose what it "sees". Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 You use the media tag <link rel="stylesheet" type="text/css" href="/common.css" media="screen, print, projection, handheld" /> <link rel="stylesheet" type="text/css" href="/screen.css" media="screen, projection" /> <link rel="stylesheet" type="text/css" href="/print.css" media="print" /> <link rel="stylesheet" type="text/css" href="/handheld.css" media="handheld" /> Know any good tutorials on this Josi...? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 http://justfuckinggoogleit.com I gave you the exact code, and the name of the property. And my name isn't "Josi". Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted February 16, 2007 Share Posted February 16, 2007 what jesirose has above looks promising. Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 what jesirose has above looks promising. Yep! It looks like the answer I've been looking for. Thanks everyone. I'd still appreciate different points of view so keep 'em coming if you have more info. Thanks again. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 but are you wondering on how to detect if the browser is a mobile phone? Exactly right! If I can detect what kind of browser is connecting I can choose what it "sees". Unfortunatley that is 'little' tougher. If you use, as I do, Jesi's method of providing style sheets for different devices then the connecting device picks the one it should use all by itself. There are how ever a couple of exceptions to this which I can't remeber the specifics of; but an example is that one of Nokias devices will always choose the 'screen' type even though it should go for the handheld...... You could check the browser details using get_browser() or maybe even the OS by using posix_uname() and echo out the corresponding style sheet based on some logic. That however would entail you loading your page on a range of devices and seeing what the output is inorder to construct that logic; unless there is a page somewhere (sure there will be) that lists all the major devices and their browser or OS details. I go with the method described by Jesi and don't care about people who buy devices that don't conform to the recommendations provided by W3C. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well. Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well. Pretty Cool "JESI" Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted February 16, 2007 Share Posted February 16, 2007 One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well. There is one reason I don't like that approach - it means twice as much work keeping your site current. 'One site fits all' is my favorite motto.... The only benefit in providing a purely free mobile zone is if you have produced WML pages... Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 One thing some places do is have a mobile subdomain, such as m.mysite.com - anyone on a handheld should go there - and then for that subdomain you force a different CSS instead of letting the device pick. I like that idea as well. There is one reason I don't like that approach - it means twice as much work keeping your site current. 'One site fits all' is my favorite motto.... The only benefit in providing a purely free mobile zone is if you have produced WML pages... Buddy, you've lost me back there ??? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 16, 2007 Share Posted February 16, 2007 Toon - no, you just need two stylesheets. Why would you have twice as much work? Either way you're creating two stylesheets - you just add a subdomain for mobile and point the DNS to the regular site... Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 16, 2007 Share Posted February 16, 2007 If you wanted a TOTALLY different page... you could use the browsers user agent string to work out which browser/device/version is accessing your page and use a location header to redirect the a different page/domain etc. Personally I think thats a crap way of doing it but its a choice I think the CSS method is good, or theres always XSLT... Quote Link to comment Share on other sites More sharing options...
sazzie Posted February 16, 2007 Author Share Posted February 16, 2007 If you wanted a TOTALLY different page... you could use the browsers user agent string to work out which browser/device/version is accessing your page and use a location header to redirect the a different page/domain etc. Personally I think thats a crap way of doing it but its a choice I think the CSS method is good, or theres always XSLT... Do you have sample code for the browser user agent? Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 19, 2007 Share Posted February 19, 2007 Just add whatever browsers you want to look for int the $browsers array... $useragent = $_SERVER['HTTP_USER_AGENT']; $browser = get_browser_name($useragent); print ("Browser name: ".$browser['browser']."<br />Browser version: ".$browser['version']."<br />"); function get_browser_name($useragent){ $browser = array ( "Opera","Msie", "Netscape", "Firefox","Safari", "Konqueror", "Mozilla" ); $info["browser"] = "Other"; foreach ($browser as $parent) { if ( ($s = strpos(strtolower($useragent), strtolower($parent))) !== FALSE ) { $f = $s + strlen($parent); $version = substr($useragent, $f, 5); $version = preg_replace('/[^0-9,.]/','',$version); $info["browser"] = $parent; $info["version"] = $version; break; // first match wins } } return $info; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.