Detecting the Safari Browser to load scripts

I needed to detect if Safari was being used as there were some issues with styling on a website I was working upon, only on Mac Safari though!!!

The following code is what I use to detect safari and load the relevant script:

<script type="text/javascript">

	if(/Safari/.test(navigator.userAgent))
	{
 		//you are using safari, or at least you CLAIM to be
		document.write('<link type="text/css" media="screen" rel="stylesheet" href="/css/safari.css" title="example" />');
	}
	</script>

Add in the tags and set the path to the correct css file you wish to load. Same concept can be used to load javascript files.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.