Forum Moderators: open
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
CSS, with support for 'media types', allows you to apply stuff like display:none;
:)
css media types display:none [google.com]
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
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.
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.