Welcome to WebmasterWorld Guest from

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)

5+ Year Member

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 Jul 27, 2013 (gmt 0)

5+ Year Member

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 Jul 27, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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.



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

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

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;

Featured Threads

Hot Threads This Week

Hot Threads This Month