Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: not2easy

Message Too Old, No Replies

Want to show div only to mobile users - best way?

     
11:24 am on Jul 27, 2013 (gmt 0)

Preferred Member from GB 

5+ Year Member

joined:Sept 29, 2009
posts:437
votes: 13


I'm guessing there are multiple ways of skinning this particular cat, which would be the best/most efficient?

I want to show a particular div to only iPad/iPod T/iPhone users.

Is this something better done with php and user agents or with CSS and exact screen sizes? Would me wanting to include iPad mean that screen sizes would be harder?
1:39 pm on July 27, 2013 (gmt 0)

Preferred Member from GB 

5+ Year Member

joined:Sept 29, 2009
posts:437
votes: 13


I've tried this and it seems to work - any reason why it's NOT a good way to do it?


<?
if (preg_match("/iP(od|hone|ad)/i", $_SERVER["HTTP_USER_AGENT"])) {
echo "iPad/iPhone";
}
else {
echo "Not iPad/iPhone";
}
?>


I've read elsewhere that browser sniffing like this is a bad idea as there could be both false positives and positive falses (do they exist? haha). If I do something based on screen size, it could become very long with the iPad, iPhone5, landscape, etc, etc.
3:33 pm on July 27, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 4, 2001
posts:2143
votes: 7


You may want to check this thread Why Do I Need A Mobile Website [webmasterworld.com]. It has some tips. You can also do a web search for open source device detection scripts.

Marshall
4:00 pm on July 31, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month

joined:Mar 30, 2006
posts:1377
votes: 51


Div targeting Ipod... Iphone..

Put your CSS into a perl/php whatever script. Detect the device via user agent and print the right CSS, like:

If Ipod: display:block/inline/tablet, whatever suites your needs.
If not ipod: display:none;
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members