KevHopwood Posted September 4, 2013 Share Posted September 4, 2013 If you have a look at The attached picture, taken on my iPad just now you will see 3 app downloads buttons. The top One links to app.php?id=android the middle one links to app.php?id=iphone and the bottom one links to app.php?id=ipad. Obviously on this occasion only the 3rd link should be visible and the other 2hidden as I am viewing on my iPad. If I was to view on my iPod touch then only the middle one should be visible. My code for the index.php page in the screenshot is this: <?PHP include_once('include/connection.php'); include_once('include/article.php'); $category = new category; $articles = $category->fetch_all(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Xclo.mobi</title> <link type="text/css" rel="stylesheet" href="other.css" /> <link rel="apple-touch-icon" href="homescreen.png" /> <link href="startup.png" rel="apple-touch-startup-image" /> <script type="text/javascript"> var bodyclass ='desktop'; if ( (navigator.userAgent.indexOf('android') != null) ) { bodyclass = 'android'; } else if((window.navigator.userAgent.match('iphone') != null)||(window.navigator.userAgent.match('iPod') != null)) { bodyclass = 'iphone'; } else if (window.navigator.userAgent.match('ipad') != null){ bodyclass = 'ipad'; } window.onload = function(){ document.body.className += ' '+ bodyclass; } <script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-34172259-1']); _gaq.push(['_setDomainName', 'xclo.co.uk']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body> <?php include_once('header.php'); ?> <div id="content"> <ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=android' " type="submit" /></li></ul> <ul class="pageitem"><li class="button iphone"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=iphone' " type="submit" /></li></ul> <ul class="pageitem"><li class="button ipad"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=ipad' " type="submit" /></li></ul> <?php foreach ($articles as $article) { ?> <ul class="pageitem"><li class="button"> <a href="list.php?id=<?php echo $article['promo_cat']; ?>"> <input type="submit" name="Submit" value="<?php echo $article['promo_cat']; ?>"/> </a></li></ul> <?php } ?> </div> <br><center> <SCRIPT charset="utf-8" type="text/javascript" src="http://ws-eu.amazon-...d9-6cf16307e855"> </SCRIPT> <NOSCRIPT><A HREF="http://ws-eu.amazon-...t">Amazon.co.uk Widgets</A></NOSCRIPT></center> <?php include_once('footer.php'); ?> </body> </html> Any ideas on how to get this to work please. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/ Share on other sites More sharing options...
Solution .josh Posted September 4, 2013 Solution Share Posted September 4, 2013 <?php $ua=$_SERVER['HTTP_USER_AGENT']; switch(true) { case stripos($ua,'android') : $device = 'android'; break; case stripos($ua,'ipad') : $device = 'ipad'; break; case stripos($ua,'iphone') : $device = 'iphone'; break; } ?> <ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=<?php echo $device; ?>' " type="submit" /></li></ul> Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/#findComment-1448124 Share on other sites More sharing options...
KevHopwood Posted September 4, 2013 Author Share Posted September 4, 2013 Thank you. This is just what I needed, Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/#findComment-1448127 Share on other sites More sharing options...
KevHopwood Posted September 4, 2013 Author Share Posted September 4, 2013 Actually. Slite problem. When viewing this in windows it still shows the download button. How do I add the else hide feature so that it ONLY shows up on a device that is necessary? Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/#findComment-1448189 Share on other sites More sharing options...
.josh Posted September 4, 2013 Share Posted September 4, 2013 come on man, make an effort. First set $device to false. then the switch stuff. Then wrap a condition around the button to check if $device is not false. Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/#findComment-1448191 Share on other sites More sharing options...
KevHopwood Posted September 5, 2013 Author Share Posted September 5, 2013 Cheers pal. I'm a css guy. I'm still learning php. I'll give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/281845-display-only-on-the-correct-devices/#findComment-1448235 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.