1. How do I detect the language setting for Safari?Safari, WebKit and Gecko based browsers support the
function showLanguage(){
var languageinfo = navigator.language ? navigator.language : navigator.userLanguage;
alert ("And the Language is: " + languageinfo);
}
Here it is in action: 2. What is the Safari user-agent string?The complete user-agent string for Safari 2 and below running on Mac OS X with a PowerPC or Intel processor:
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/XX (KHTML, like Gecko) Safari/YY
Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/XX (KHTML, like Gecko) Safari/YY
For each, "XX" is the build version of the web technology framework used by Safari and "YY" is the build version of the Safari application. The complete user-agent string for Safari 3 running on Mac OS X with a PowerPC or Intel processor and Windows: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_5_3; en-us) AppleWebKit/XX (KHTML, like Gecko) Version/ZZ Safari/YY Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/XX (KHTML, like Gecko) Version/ZZ Safari/YY Mozilla/5.0 (Windows; U; Windows NT 5.1; en-us) AppleWebKit/XX (KHTML, like Gecko) Version/ZZ Safari/YY Safari 3 or greater on all platforms contains the additional The complete user-agent string for Safari 3 running on iPhone: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/XX (KHTML, like Gecko) Version/ZZ Mobile/WW Safari/YY Safari 3 on iPhone contains the additional If you need to detect the version of the browser accessing your site, use the The WebKit project page provides an excellent library you can leverage on your site -including detection of Safari on mobile devices. For example: And remember, since the rendering engine used by Safari behaves most like Netscape, the Safari JavaScript engine will report
Show your browser's value for the JavaScript object: 3. Does Safari support DHTML?Safari supports DHTML through the W3C DOM-2, which provides access to almost every element on a page via JavaScript. If you'd like to learn more, check out Apple Internet Developer's two-part series on working with the DOM-2: Part I, Part II. When testing for DHTML support in your scripts, check for the
if (document.getElementById)
{
// browser supports W3C DOM
}
Note that older browsers support DHTML through other DOMs. Internet Explorer 4 supported a DOM that used
if (document.getElementById || document.all || document.layers)
{
//browser can handle DHTML
}
Here's how it would look: 4. How do I determine methods for accessing objects?Object detection is the best way to test a browser's capabilities. The previous example provides a brief example of object detection: the existence of an object ( 5. How do I prevent my pages (and cookies) from being cached in Safari?Safari achieves much of its performance through efficient use of content caching. If you have pages you wish to prevent from being cached, including those that write out cookies, be sure to write the following headers when serving your pages:
// PHP example - include at the top of your pages
<? php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
// JSP example - call before writing page content
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching on a proxy server as well
Safari's Back/Forward cache (the cache pulled from when a visitor presses the Back or Forward browser buttons) can also be thwarted by insuring that your page contains a frame. Frame-based pages are never stored in the back / forward cache and you can insure your non-frame based page behaves similarly by adding the invisible iframe below. <iframe style="height:0px;width:0px;visibility:hidden" src="about:blank"> this frame prevents back forward cache </iframe> 6. How do I test for cookies using JavaScript?Safari ships with a conservative cookie policy which limits cookie writes to only the pages chosen ("navigated to") by the user. This default conservative policy may confuse frame based sites that attempt to write cookies and fail. Be sure to check the Safari preferences before assuming that your cookies are not written due to a bug; it may just be the users preference. The following functions set a cookie and test for its existence:
function testCookies() {
var exp = new Date();
exp.setTime(exp.getTime() + 1800000);
// first write a test cookie
setCookie("cookies", "cookies", exp, false, false, false);
if (document.cookie.indexOf('cookies') != -1) {
alert("Got Cookies!");
}
else {
alert("No Cookies!");
}
// now delete the test cookie
exp = new Date();
exp.setTime(exp.getTime() - 1800000);
setCookie("cookies", "cookies", exp, false, false, false);
}
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
document.cookie = curCookie;
}
Give it a try: 7. How do I add a Favicon (the small icon in the address bar)?Putting the following lines within your <head> tag will add a Favicon to your site: <link rel="icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> If you'd like to learn how to create a Favicon, take a look at this tutorial. 8. What version of Java does Safari use for running Applets?Safari uses the most current version of Java delivered with Mac OS X. Updates to Java are periodically available via software update or for download from the Java technology page. Review the Identifying Java on Mac OS X Technical Note to learn how to identify the particular version of Java running your applet. Use the Java Plugin Settings application ( Applications/Utilities/Java/ ) to display the Java Console while running applets in Safari and to select Safari's default JVM. 9. How do I determine if Java is Available?Safari supports Java Applets however some users may prefer to disable its use. Use the Here it is in action: 10. How does Safari handle server timeouts?Safari on pre Mac OS X 10.3.6 systems will time out if it does not receive a response to an HTTP request or if server data transmission stops for 60 seconds. Safari on Mac OS X 10.3.6 and above effectively removes the 60 second limitation by setting the response timeout value to one year. That should be plenty of time for a server-side process to complete! 11. What type of plug-ins does Safari support?All versions of Safari support Netscape-style plug-ins. In additon to Netscape-style plug-in support, Safari 1.3 and above on Mac OS X supports Cocoa plug-ins. While not cross platform, Cocoa plug-ins are easy to create and allow your plug-in to leverage all of Cocoa's frameworks. For more on writing Cocoa plug-ins, review the WebKit Plug-In Programming Topic and try the sample plug-ins available in the WebKit examples directory provided with Xcode. For more on writing Netscape-style plug-ins for Safari, see Apple's Technical Note on Browser Plug-ins for Mac OS X and Netscape's definitive Plug-in Guide. A very simple Sample plug-in is available, however you will need the appropriate header file "npapi.h" from Netscape to build the project yourself. With the transition to Intel-based processors, developers should always create universal binaries for plug-ins written with Carbon, Cocoa, or BSD APIs. For information on how to create universal binaries, see Universal Binary Programming Guidelines. 12. Where should Safari plug-ins reside?To insure that a given plug-in is available to all users of Safari as well as other WebKit-based applications, browser plug-ins should be placed in the '/Library/Internet Plug-Ins/' directory. For Safari 3.0 on Windows, browser plug-ins may be placed in the 'C:\Program Files\Safari\plugins\' directory or any other appropriate location provided that the location is placed in the registry under the registry key '\Software\MozillaPlugins'. 13. How do I ensure that my pages will work in Safari?Safari renders HTML in conformance with the W3 specification. You can validate your pages for compliance with the W3 specification via the web-based W3 HTML Validator. If you want to run the validator inside your firewall, follow this recipe and validate yourself! Be sure to have a DTD defined in your page, pass the validation and you too can proudly display: In addition, Bookmarklets or Favlets are extremely useful tools to keep handy during your page development. Drag the links below to the Safari Bookmarks Bar to save as a Bookmark then use them to help you debug.
14. How do I debug JavaScript in Safari?Safari's "Develop" menu allows you to turn on the viewing of JavaScript errors and more. To display the Develop menu in Safari 3.1 or higher, select the checkbox labeled "Show Develop menu in menu bar" in Safari's Advanced Preferences panel. Safari 1.3 and above supports explicit logging of arbitrary information - similar to Objective-C NSLog() - function by using
if(window.console) {
window.console.log("I think therefore I code!");
}
else {
alert("I think therefore I code!");
}
Using Safari 1.3 or above? Open the JavaScript Console and click to see it in action! 15. How do I report a Bug in Safari?If you have found a bug in Safari, we want to know! Please review the basics on how to log bugs and remember, the most important aspect of your bug report is a concise reproducible example that demonstrates the problem. Bugs that can reproduced independent of your site or product are infinitely easier to fix. Looking to certify your web-based application or online service with Safari and don't know where to start? Sign up as a developer and send us a note. 16. What CSS properties are supported in Safari?Safari is designed to provide the most complete implementation of the CSS specification. There are however, some CSS properties that are not available or only partially implemented. If your site is utilizing CSS that doesn't appear to work in Safari, please review this list as a sanity check. 17. Why are my Pop-Up Windows not appearing?Safari has implemented a pop-up window blocker in order to minimize the distracting pop-up windows many sites use for advertising. The pop-up blocker will filter all pop-ups, except those triggered by a user action, such as a mouse click or a key press. Pop-ups triggered directly from <script> tags, from the onLoad handler, from the onUnload handler, or from timers are blocked. Be sure to select the "Block Pop-Up Windows" option during QA to be sure that your users don't lose functionality when this very popular feature is used. 18. Does Safari support Live Connect?Yes! - Safari 1.2's implementation supports the most popular requirement of Live Connect - communication between Java Applets and JavaScript on the same page. See it in action or download the sample and create your own. Safari's implementation supports communication between Cocoa and Netscape style plug-ins and Javascript in Safari version 1.3 or higher. 19. Does Safari support XMLHttpRequest objects?Yes again! - Safari 1.2's implementation follows the Mozilla model and successfully runs the Mozilla examples at Mozilla.org. Content fetched into an xmlhttprequest object is often XML, however it may contain any kind of textual data and is referenced via the same DOM calls as the document content on a visible web page. Read this article to learn how to keep web pages connected to XML data on a server using the XMLHttpRequest object. 20. Does Safari support Tool-Tips?Safari supports the display of floating text above elements on the page when the 'title' attribute is set. Some browsers may display this "tool-tip" when the 'alt' attribute is populated however, the 'alt' attribute has been created to provide information to screen reading applications for the visually impaired and be used only for such purposes. Move your mouse over the image below to see it in action. 21. Does Safari support XSLT?Safari 1.3 and above supports XSL transformations of XML pages at load time. XSLT support is limited to XSL page processing instructions embedded at the top of an XML page: <?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="your_transform_file_here.xsl" ?> XSLT is not accessible via JavaScript XSLTProcessor for arbitrary XML transformations in an HTML page. 22. How do I tell Safari I have an RSS feed?Safari 2.0 and above indicates to a user that the page or the site they are on provides an RSS rendition of its content via the link element: <head> <link rel="alternate" type="application/rss+xml" title="RSS" href="/main/rss/hotnews/hotnews.rss"> <link rel="alternate" type="application/rss+xml" title="RSS" href="/main/rss/hotnews/pr.rss"> </head> Safari's default preferences are set to poll bookmarked RSS feeds every 30 minutes using conditional GET requests allowing Safari RSS to only pull data from servers that indicate a feed has been modified since the last check. Safari's default preferences are set to cache feeds for a period of two weeks. 23. Does Safari work with .NET and ASPX based sites?Naturally! Safari supports any web server architecture capable of deploying pages in a multi-vendor browser environment. Be sure to avoid non-standard features in your development environment that lure you into producing a product that is browser specific. Improper .NET / ASPX server configuration can account for incompatibilities; For example, the machine.config file contains a <browserCaps> section for sniffing the browser which may not be configured to support any non-IE browser. As a result, developers have reported improperly sized or positioned multi-line TextAreas (<asp:TextBox></asp:TextBox>). ASP.net developers should check out this updated <browserCaps> that supports Mozilla/Firefox, Netscape, Opera, Safari and Konqueror. 24. Does Safari support Frames, Framesets and iFrames?Yes, every version of Safari supports the <frame>, <frameset> and <iFrame> elements. 25. What's different about Safari running on an Intel-based Macintosh?From the typical web page developers perspective - nothing. Web sites and web applications built with HTML, CSS, and Java Script just work. If your pages rely on browser plug-ins, be sure that the your plug-ins are built to run on any Macintosh. Browser plug-ins are platform specific and therefore need to be distributed as a Universal Binary in order to run on any Macintosh - regardless of the processor.
|