Help - Search - Members - Calendar
Full Version: browser detection
Movable Type Community Forum > Additional Resources > Tips and Tricks
akalsey
You can do this with JavaScript. There are hundreds of scripts available that do this. Try searching Google for javascript browser redirect or something similar.
loopyca
Brent:

Here is a script snippet I had on my computer - give it a try if you like. This script would be placed within the < HEAD > and < /HEAD > tags of each page:

CODE
<script>

var browser_type=navigator.appName
var browser_version=parseInt(navigator.appVersion)

//if NS 6
if (browser_type=="Netscape"&&browser_version>=5)
window.location.replace("http://URLFORNETSCAPE6")
//if IE 4+
else if (browser_type=="Microsoft Internet Explorer"&&browser_version>=4)
window.location.replace("http://URLFORMSIE4+")
//if NS4+
else if (browser_type=="Netscape"&&browser_version>=4)
window.location.replace("http://URLFORNETSCAPE4")
//Default goto page (NOT NS 4+ and NOT IE 4+)
else
window.location="http://DEFAULTURLFOROTHERBROWSERS"
</script>


Hope this helps!
Loopy
brent
i am doing some things that only seem to work in IE6...is it possible to have the HTML detect what browser and version is being used, and if its not IE6 it will redirect them to a different place???
kadyellebee
Also, here's a thread at scriptygoddess that has some code and discussion on how to do this smile.gif

Kristine
buhlogged
If you can run CGI/SSI on your server, then you'd do well to detect a user's browser through a simple script which will assign a stylesheet which works best with it. I use separate CSS for IE5+, Opera, NS4 and Gecko-based browsers myself. Your stylesheet.cgi can look something like this:

CODE
#!/usr/local/bin/perl
($TEST = $ENV{'HTTP_USER_AGENT'});

$site = "http://path/to/stylesheet/directory";

$netscape_4 = "$site/ns4.css";
$iexplorer_5up = "$site/ie5.css";
$gecko = "$site/gecko.css";
$opera = "$site/opera.css";
    
$cssdoc = $netscape_4 if $TEST =~ /Mozilla\/4/;
$cssdoc = $iexplorer_5up if $TEST =~ /MSIE/;
$cssdoc = $gecko if $TEST =~ /Gecko/;
$cssdoc = $opera if $TEST =~ /Opera/;


print "Content-type: text/html\n\n";  
print "<link rel=\"stylesheet\" href=\"$cssdoc\" type=\"text/css\" />";
exit();


(Make sure you've got the path to perl on your server correctly - you may have to change it. Also, you must upload ns4.css, ie5.css, etc. to the server.)

Then you call the script in the <head> section of your document:

CODE
<!--#exec cgi="/cgi-bin/stylesheet.cgi"-->


The nice thing about doing script detection this way is that instead of doing a completely new html document, you only have to make a single stylesheet for every browser you want to detect. Saves a lot of time and space. Works like a charm, too.

Hope this helps.

-Chris
JakeMetcalf
The Web Standards Project has a really good method that detects Netscape 4 and other non DOM compliant browsers
http://www.webstandards.org/act/campaign/buc/tips.html

Try Putting this in your Javascript tag after you last element.
CODE
if (!document.getElementById) {
   window.location =
    "http://www.8bitjoystick.com/post/upgrade.htm"
}
loopyca
Or you could 'screw' the old browser people and just have a message appear at the top of every page *if* they are using a non-compliant browser.

This is the code you'd put just under the < BODY > tag:
CODE
<P class="oldbrowser">
This site will look much better in a browser that supports web standards - you are seeing this message because your's doesn't. Our content may be visible - but perhaps not beautiful.
<A HREF="http://webstandards.org/act/campaign/buc/" TARGET="_blank">Go on... upgrade... it won't hurt</A>!</P>


And then in between your < HEAD > & < /HEAD > tag, you'd put:
CODE
<STYLE type="text/css" media="all">
.oldbrowser
{
display: none;
}
</STYLE>


Loopy
medic119
This is absoltely ridiculous.

CSS is a standard and if you are going to build a browser it oought to follow at least the real standards (i am talking proprietary MS "standards" etc).

The same template should look the same in all browsers regardless!!!

I am having this problem right now.  My site is really screwed using Mozilla.  I have all standard CSS tags and nothing special.
T-DoG
QUOTE
This is absoltely ridiculous.

CSS is a standard and if you are going to build a browser it oought to follow at least the real standards (i am talking proprietary MS "standards" etc).

The same template should look the same in all browsers regardless!!!

I am having this problem right now.  My site is really screwed using Mozilla.  I have all standard CSS tags and nothing special.

Mozilla has much stricter standards compliance than IE6 across the board.  Mozilla is probably rendering your page correctly and IE is not; you're just used to seeing it with IE.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.