Forum Moderators: open

Message Too Old, No Replies

browser detection

text browsers

         

Matthew1980

9:52 pm on Dec 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there People of webmaster world!

I would like to know how to detect a text browser to enable me to call specific files pertaining to browser type with the use of php (I will ask on the other forum for that), example, text only browser would not display captcha files, so a bit of trickery with js could determine that and then help to call a separate file with related content.

I hope I make sense!

Thank you in advance,

MRb

lavazza

10:35 pm on Dec 16, 2009 (gmt 0)

10+ Year Member



Javascript is for behaviour
CSS is for presentation

CSS, with support for 'media types', allows you to apply stuff like display:none;

:)

css media types display:none [google.com]

Matthew1980

8:15 am on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Lavazza,

Thanks for the reply, im not having issues with the aesthetics, I need to find a way of checking if the user has mozilla;netscape;IE or other browser type, and then display the pages content according to the capability of the users browser, I understand I need javascript, but, for browsers like Lynx there doesnt seem to be a java script method of detection.

Cheers,

MRb

Fotiman

2:22 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Haven't had a chance to put much thought into this, but perhaps you could try creating a new Image, assign it a src (point to a tiny 1x1px image), and then check some properties on the image? Just an idea.

Demaestro

3:41 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hey Matthew,

Here is a way of outputting the browser type to the screen so you can see what it is.

<script type="text/javascript">
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);

document.write("Browser name: "+ browser);
document.write("<br />");
document.write("Browser version: "+ version);
</script>

You can mold this using 'if' statements to check for certain browsers and then take different actions based on the browser type.

rocknbil

6:55 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A point to consider, if the browser is text only, it's not likely it will execute Javascript either . . .

You'd probably be best doing this via the USER_AGENT environment variable in PHP, although I don't have specific instances of code or sample agents. I stopped doing **anything** via browser identification ages ago, as browsers change almost monthly and requires continual maintenance.

A better idea (might?) be similar to what we do for most JS. That is, instead of testing browser or version, you just look for the tools you need. For example,

if (document.getElementById) {
// this is a modern browser, we can do stuff
}
else { alert('Yo! Update your browser!'); }

So within PHP, maybe you can do a test, something like

<img src="img-test.php">

And if img-test.php gets requested, this user agent is attempting to display an image, so we might assume it can do so. How you'd get that message from img-test.php to the script containing it is something I haven't sorted yet, but you get the idea . . . we are testing for ability to display images, not browser.

Matthew1980

11:15 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Guys,

Thanks for the messages, I will cobble something together tomorrow and see what I can come up with, I will post at some stage with any success I get, if any.

Thanks,

MRb