homepage Welcome to WebmasterWorld Guest from 54.204.77.26
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Mobile Internet / Mobile Web Site Design and Development
Forum Library, Charter, Moderator: open

Mobile Web Site Design and Development Forum

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




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

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?

 

ChanandlerBong




msg:4597013
 1:39 pm on Jul 27, 2013 (gmt 0)

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.

Marshall




msg:4597028
 3:33 pm on Jul 27, 2013 (gmt 0)

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

explorador




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

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;

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Mobile Internet / Mobile Web Site Design and Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved