views:

913

answers:

4

What is iPhone's browser tag and how iPhone optimized web site is different from a usual mobile web site?

Thanks!

+1  A: 

Nettuts has a great introduction to web-developement for iPhone. You find it here

This is the specific code you asked for (taken from that article):

<!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"-->   

<!--  
place iPhone code in here  
-->   

<!--#else -->   

<!--  
    place standard code to be used by non iphone browser.   
-->   
<!--#endif -->
Espenhh
+1  A: 

Apple defines the user agent here.

This field is transmitted in the HTTP headers under the key "User-Agent"

Jason Cohen
+2  A: 

Apple has some excellent guidelines for iPhone web page development here:

Safari Web Content Guide for iPhone

From my brief reading of it, here are a key elements to look out for:

  • The way the "viewport" and scrolling works is a bit different due to the small screen size. There are custom META tags that let you adjust this automatically when someone comes to your page.
  • Beware pages that use framesets or other features that require the user to scroll different elements on the page, because the iPhone does not display scrollbars.
  • If you expect people to bookmark your page on the iPhone, there's a custom META tag that lets you specify a 53x53 icon that will look nicer than the typical favorite.ico.
  • Avoid javascript that depends on mouse movement or hover actions to make things happen, they won't work right on iPhone.
  • There are some custom CSS properties that allow you to adjust text size and highlight color of hyperlinks on the iPhone.
  • There are other key HTML/Javascript features that they tell you to either favor or avoid as well.
Tim Farley
A: 

Better Solution:

*

  (NSString *)flattenHTML:(NSString *)html {

  NSScanner *theScanner; NSString *text = nil;

  theScanner = [NSScanner scannerWithString:html];

  while ([theScanner isAtEnd] == NO) {

  // find start of tag
  [theScanner scanUpToString:@"<" intoString:NULL] ; 


  // find end of tag
  [theScanner scanUpToString:@">" intoString:&text] ;


  // replace the found tag with a space
  //(you can filter multi-spaces out later if you wish)
  html = [html stringByReplacingOccurrencesOfString:
                     [ NSString stringWithFormat:@"%@>", text]
               withString:@" "];

  } // while //

  return html;

}

Jimit