Menu
Hi guys
I want to include a separate style sheet for a Safari Web Browser on a MAC machine.
Does anyone know how to do this?
Ty
[CODE]
/*******************************************************************
This function returns the browser name as a string
*******************************************************************/
function getBrowserName()
{
var name = "Unknown";
if(navigator.userAgent.indexOf("MSIE")!=-1)
{
name = "MSIE";
}
else if(navigator.userAgent.indexOf("Firefox")!=-1)
{
name = "Firefox";
}
else if(navigator.userAgent.indexOf("Opera")!=-1)
{
name = "Opera";
}
else if(navigator.userAgent.indexOf("Chrome") != -1)
{
name = "Chrome";
}
else if(navigator.userAgent.indexOf("Safari")!=-1)
{
name = "Safari";
}
return name;
}
/*******************************************************************
This function returns the browser version as a string
*******************************************************************/
function getBrowserVersion()
{
var version = "0";
//look for IE browser
if (navigator.userAgent.indexOf("MSIE")!=-1)
{
var temp = navigator.userAgent.split("MSIE");
version = temp[1].substring(0, temp[1].indexOf(";"));
//alert("You are using Microsoft Internet Explorer version " + version);
return version;
}
//look for Firefox browser
if(navigator.userAgent.indexOf("Firefox")!=-1)
{
var versionIndex=navigator.userAgent.indexOf("Firefox")+8;
if (parseInt(navigator.userAgent.charAt(versionIndex))>=1);
{
version = navigator.userAgent.substring(versionIndex, versionIndex+7);
}
//alert("You are using Firefox version " + version);
return version;
}
//look for Opera browser
if(navigator.userAgent.indexOf("Opera")!=-1)
{
//check if Opera 10+
if(navigator.userAgent.indexOf("Version/")!=-1) {
var temp = navigator.userAgent.split("Version/");
version = temp[1];
}
else { //we have Opera 9-
var temp = navigator.userAgent.split("Opera");
version = temp[1].substring(1, temp[1].indexOf(" "));
//alert("You are using Opera version " + version);
}
return version;
}
//look for Chrome Browser
if(navigator.userAgent.indexOf("Chrome")!=-1)
{
var temp = navigator.userAgent.split("Chrome/");
version = temp[1].substring(0,temp[1].indexOf(" "));
//alert("You are using Chrome version " + version);
return version;
}
//look for Safari browser
if(navigator.userAgent.indexOf("Safari")!=-1)
{
var temp = navigator.userAgent.split("Version/");
version = temp[1].substring(0,temp[1].indexOf(" "));
//alert("You are using Safari version " + version);
return version;
}
}
*************************************************************************************/
var browserName = getBrowserName();
var browserVer = parseFloat(getBrowserVersion());
//var browserVer = 6;
//alert("Browser = "+browserName+"nnVersion = "+browserVer);
var isBrowserSupported = false;
function setCSSforBrowser(cssPath)
{
if(browserName == "MSIE" && browserVer >= 8)
{
//we have IE8 or higher
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_IE8.css" />');
isBrowserSupported = true;
}
else if(browserName == "MSIE" && browserVer >= 7)
{
//we have IE7 or higher
/*
alert("Your browser is Microsoft Internet Explorer version 7 !!!!"+
"nnYour screen width :t" + screen.width + " pixels." +
"nYour screen height:t" + screen.height + " pixels." +
"nnThis page is optimised for Microsoft Internet Explorer V7 nwith screen size 1280 x 1024 pixels.");
*/
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_IE7.css" />');
isBrowserSupported = false;
}
else if(browserName == "MSIE" && browserVer <= 6)
{
//we have IE6 or lower
alert("** Warning **nnYour browser is Microsoft Internet Explorer version 6 or lower.nnThis website has features not supported by IE v6nand is best viewed with:"+
"nnInternet Explorer v7+nFirefox v2+nOpera v9.63+nSafari for Windows v3.1+nGoogle Chrome v2+nn"+
"Please consider updating or changing your browsernto one of the above.nnThank you.");
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_IE7.css" />');
isBrowserSupported = false;
}
else if(browserName == "Firefox")
{
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_FF3.css" />');
if(browserVer >= 3.6)
isBrowserSupported = true;
else
isBrowserSupported = false;
}
else if(browserName == "Safari")
{
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_SAF.css" />');
if(browserVer >= 4)
isBrowserSupported = true;
else
isBrowserSupported = false;
}
else if(browserName == "Opera")
{
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_OP.css" />');
if(browserVer >= 10)
isBrowserSupported = true;
else
isBrowserSupported = false;
}
else if(browserName == "Chrome")
{
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_GC.css" />');
if(browserVer >= 2)
isBrowserSupported = true;
else
isBrowserSupported = false;
}
else //we have an unsupported browser - use the FF css and hope for the best !!!
{
document.write('<link rel="stylesheet" type="text/css" href="'+cssPath+'wpc_FF3.css" />');
isBrowserSupported = false;
browserName = "Unsupported";
browserVer = "Unknown";
}
//reset the MSIE browser name
if(browserName == "MSIE") browserName = "Internet Explorer"
}
/************************************************************************************
This function checks if the user's browser is supported or not
************************************************************************************/
function checkForUnsupportedBrowser()
{
if(!isBrowserSupported)
{
alert("** Warning **nnThis website is best viewed with:"+
"nnInternet Explorer v7nFirefox Portable Edition v3.0.5nOpera v9.63nSafari v3.1nn"+
"It appears your browser is not one of the above.nn");
}
}
//----------------------------------------------------------------------------
//** This function gets a browser's viewport width and height
//----------------------------------------------------------------------------
function getViewportInfo(minWidth)
{
var viewportwidth = 0;
var viewportheight = 0;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth,
viewportheight = document.documentElement.clientHeight
}
// older versions of IE
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
viewportheight = document.getElementsByTagName('body')[0].clientHeight
}
//alert user if his broweer window is too small
if(viewportwidth > 0 && viewportwidth < minWidth)
{
alert('** Warning ** nnYour browser width is '+viewportwidth+' pixels wide.'+
'nnYour browser needs to be at least '+minWidth+' pixels wide to view this page correctly.'+
'nnPlease maximise your browser window or increase your monitornscreen width to at least '+minWidth+' pixelsnn');
}
}
[/CODE]
Imo the overwhelming vast majority of users use either IE or FF and have JS enabled.[/QUOTE]
0.1.9 — BETA 5.16