First of all, that's an invalid script tag and will do nothing in Safari. The test appears to be valid, but creates an undeclared global variable, not very good form and can result in unexpected problems. If used on an XHTML DOCTYPE page, it may need !CDATA comment delimiters (these will not harm other DOCTYPE's).
So I'd suggest:
Code:
<script type="text/javascript">
/* <![CDATA[ */
if(window.devicePixelRatio){
document.write('<link rel="stylesheet" href="safari.css" type="text/css">');
}
/* ]]> */
</script>
But this will also work for Chrome! Perhaps other WebKit based browsers like Konqueror would also be included. If there are items in the stylesheet that could cause problems for Chrome, etc., we can add:
Code:
<script type="text/javascript">
/* <![CDATA[ */
if(window.devicePixelRatio && /Apple/.test(navigator.vendor)){
document.write('<link rel="stylesheet" href="safari.css" type="text/css">');
}
/* ]]> */
</script>
to eliminate Chrome and all others not specifically Safari.
However, if all of your special styles are either -webkit- or true css3 styles and work in Safari 3, they will probably work in those other browsers anyway.
Bookmarks