|
![]() | |||||||||||
![]() | |||||||||||
Web developers have applauded the standards-based approach that Apple has taken in designing Safari, because it means supporting Safari is relatively simple and painless. Most developers are happy to follow the W3C guidelines and have their pages "just work," with no need for browser-specific HTML. However, Safari has the features you'd expect of a modern browser plus a few unique ones; understanding these, as well as a few Safari development tricks, will ensure your web property works exactly the way you and your users expect. This article takes a look at some of the specifics of how the Safari browser behaves from a development standpoint, valuable tricks that you should be aware of, and specialized behavior. Throughout the article are useful JavaScripts that highlight features of the Safari browser. The source code for these reusable scripts is all contained within the <head> section of this page. Detecting User Information Safari identifies itself with the following User-agent string:
where XX is the version of Apple's web technology used by Safari and YY is the version of the Safari application. The AppleWebKit/XX portion identifies the rendering engine and can be used to pinpoint the exact version of Safari that is being used. Here is code to check your user-agent string:
Here is the function displayed in action: Various aspects of the browser can be retrieved as values of the
Here it is in action: Show your browser's value for navigator. This function detects explicitly whether the user is using a browser based on the Web Kit:
And here it is displayed in action: To detect a Safari user's preferred language, use the
JavaScript can be used to test a user agent's object capabilities. This Internet Developer Object Detection article explains object detection and how it can be more useful than browser sniffing. Here is an example of using object detection to test if a browser has support for DHTML:
This checks for the various DOM objects used by various browsers to
provide DHTML support— Cookies, Caching, and Address Bar Icons Safari (and other browsers) speed up user-end response times by caching static and semi-static content, including cookies. This behavior can be prevented by passing the following HTTP headers to the browser:
This can be done with PHP as follows:
Cookies can be set and retrieved in Safari (and other browsers) using the following JavaScript snippet:
This button checks your browser for cookies: Favorite Icon Safari is compatible with the favorites-icon standard, which displays a 16-by-16-pixel icon in the address bar, like this one: ![]() The icon is supplied by the website. In order to provide a favorites icon to compatible browsers, place the following code in the HEAD area of HTML documents:
See the article on Hotwired's Webmonkey site: All About the Favorites Icon to learn how to create and display favorites icons. Java, JavaScript, CSS, and Plugins Since the release of Java 1.4.1
for Mac OS X, Safari can work with either Java 1.4.1 or 1.3.1. The
Java 1.4.1 plugin, All plugins for Safari reside in the Safari offers as complete as possible an implementation of the Cascading Style Sheets standard. There are some lacunae and caveats, detailed in the Internet Developer article, CSS Support in Safari. In order to debug JavaScript scripts in Safari, it can be helpful to view errors encountered by the scripts in the debugging console. To enable this, execute the following command from the Terminal:
This causes Safari to include a Debug menu. Selecting "Log JavaScript Exceptions" from this menu allows the errors to be viewed in the Console application. Miscellaneous Safari Tips Safari incorporates a built-in pop-up window blocker, which disables
pop-up windows triggered by <script> tags, the Safari's time-out behavior is as follows: the browser will time out if it does not receive a response to an HTTP request or if server data transmission stops for 60 seconds. Safari follows the HTML specification in rendering Web pages. Pages can be tested for standards compliance, and hence Safari compliance, using the W3C's HTML Validator. |
![]() | |
![]() | |
![]() | |
Get information on Apple products.
Visit the Apple Store online or at retail locations. 1-800-MY-APPLE Copyright © 2003 Apple Computer, Inc. All rights reserved. | Terms of use | Privacy Notice |