...

View Full Version : Change Code for specific browsers



vorl
08-10-2005, 12:35 AM
Hey

Im aiming my site for firefox and ie but have found i need to change the code appropriately according to the diff browser. Is it possible to detect what browser the user is using and use the code I set for that browser on that page. For example if the browser used is firefox the browser will only use the code i set for firefox and vice versa.

thanks

vorl

Basscyst
08-10-2005, 01:05 AM
Yep, it sure is. It's often called code forking, you really want to do it as little as possible. Most people will test for a property or method that is only available in a certain browser.

For example:



var ie=document.all;

if(ie)
{
do ie stuff
}
else
{
do this stuff
}


More appropriatly to test for IE (sometimes opera will disguise itself as IE):



var ie=(document.all && !window.opera)?1:0;
if(ie)
{
do ie stuff
}
else
{
do this stuff
}


Basscyst

vorl
08-10-2005, 01:50 AM
hi Basscyst

thanks for the response. would doing this slow down the loading of the page?

also could you show me how to detect firefox?

thanks for the help :thumbsup:

vorl

Lerura
08-14-2005, 12:01 AM
var ff=(navigator.userAgent.indexOf('Firefox')!=-1?1:0);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum