Ever wanted to access an iPhone-only site like iphone.beejive.com? Not surprisingly, I couldn't get JiveTalk for the iPhone to work in Firefox (using an iPhone user-agent string), but it worked fine in Safari. I tested this with Safari 2.0.4 and Safari 3.0.2 on OS X 10.4.10 and it worked fine, but Safari 3.0.2 on Windows seems to ignore the CustomUserAgent parameter. In other words this only works on a Mac.
Make sure you have an iPhone user agent handy, like this one:
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3 |
- First, quit Safari if it's running.
- If you haven't done so already, enable the Safari debug menu, this will let you change your user agent back easily and give you some other useful options.
- On a Mac1 open a new terminal and type:
defaults write com.apple.Safari IncludeDebugMenu 1
- Next you'll set the
CustomUserAgentkey to change the Safari user agent. From the same terminal window type:defaults write com.apple.Safari CustomUserAgent '"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3"'
- Use this bookmarklet to resize the viewport to 320 x 396:
javascript:void(window.resizeTo(self.outerWidth-self.innerWidth+320,self.outerHeight-self.innerHeight+396))
- Browse to http://iphone.beejive.com/ or some other iPhone-only site
Note: If you don't have a vertical scrollbar the first time you run the bookmarklet, and then one is displayed it'll create a horizontal scrollbar which messes up the display. - When you're ready to switch back to the default user agent just open the Debug menu and select User Agent > Automatically Chosen.
- To enable the Safari Debug menu on Windows see my earlier post [back]



July 20th, 2007 at 6:38 am
[...] Using Safari to mimic the iPhone browser | corey gilmore's blog (tags: iphone development iphoneapp code mac osx safari) [...]
May 26th, 2008 at 5:00 am
Hey Corey, nice little bit of code, works a treat. Question for you though, how do you reverse step 4?
Thanks
May 26th, 2008 at 6:20 pm
To reverse step 4 I wrote:
defaults write com.apple.Safari CustomUserAgent '""'
It worked fine…
May 27th, 2008 at 10:14 am
You can also use
to remove the key.
June 10th, 2010 at 2:33 pm
has anyone tried this on windows and actually got it working? I have safari for windows (v.5.0) running on Windows 7. so I located the "com.apple.Safari.plist" file from C:\Users\\AppData\Roaming\Apple Computer\Preferences directory and added the follwoing entry.
CustomUserAgent
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A538b Safari/419.3
when I open safari back it seems to default back even if the Developer menu is disabled. Through the plist file it takes the changes I make like hide/show developmer menu etc. but seems ignor the CustomUserAgent. Is this a known issue or off any work arround???
March 1st, 2011 at 1:25 pm
Never even thought to try and look at it from the iphone view.