So it is very difficult to design a webpage which looks/works good in all browsers.
But anyway we should make the website to look good in all browser to reach maximum users.
So even we can write separate code for each browser and we can call it is based on the browser type of the user. And therefore a function for finding the browser type of the user is necessary.
The above sample code will just detect whether the browser is firefox or others.
You can enhance it to include all other browsers also.
The try/catch is necessary here as the browser finding code supported by one browser may not be supported by another.