How do I detect the browser from the server?

3

Using a lightweight server that does basic serving of pages and doesn't have a api call for browser detection (like in ASP.NET, for example).

What is the best way to go about finding what browser the user is using?

Just parse the request header or is there some other way?

EDIT
Server:
http://www.goahead.com/

Tommy

Posted 2011-05-05T18:10:03.340

Reputation: 599

1What server are you using? – Adam Prax – 2011-05-05T18:20:21.077

@Adam, see edit – Tommy – 2011-05-05T18:28:10.507

Answers

1

If the user requests the page that is present on the server, then you can write your own Browser Detection Script. It can be in any language, Javascript, C# .Net, Or JSP etc.,

Here is the sample, that is in Javascript:

<script type="text/javascript">

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("example").innerHTML=txt;

</script>

try pasting this in the html of the page. Then this will detect the browser. If you need any, do comment

MoG

Posted 2011-05-05T18:10:03.340

Reputation: 1 248

what can I do on the server side with this? Do I parse it? Thank you. – Tommy – 2011-05-05T18:33:42.363

This doesn't seem to be what the OP is looking for. He wants to determine the browser on the server-side, rather than on the client-side. Javascript is run inside the user's browser, not by the server. – Adam Prax – 2011-05-05T18:56:07.763

On your server, you will be having HTML Pages right. Embed this code into the HTML Page. This will be detecting the Browser. So once you detect the browser, you can proceed. Your Que says, "What is the best way to go about finding what browser the user is using?" So here is the solution. You have find out the user browser. ! – MoG – 2011-05-05T18:56:14.647

@Adam Parx: To detect the browser of the client, client needs to request from the server initially, lets say, user requested the above javascript containing html page. Now as soon as the page is loaded, postback the page data to Server. Bingo, you have detected the user browser. – MoG – 2011-05-05T18:58:30.477

1

According to the information in the link you provided, your webserver supports classic ASP.

You can use ASP to grab and parse the user agent string to determine the client's browser.

<%
user_agent = request.servervariables("HTTP_USER_AGENT")
response.write(user_agent)
%>

Adam Prax

Posted 2011-05-05T18:10:03.340

Reputation: 921