Where can I get code to block certain Web browsers from accessing my web site?
I would like to block web users on Netscape Navigator from accessing my Web site. (I've seen web pages that have a "your browser is not supporter" block). Where can I get that code and/or how do I set it up?
Public Comments
- I am assuming that you are a techie. Typically, you can do this using JavaScript in your HTML code. So when the browser attempts to render the page the JavaScript will kick in and block the user -- you may also have to include redirect to ensure that the user is always directed away from your website, in the event that the browser is not a desirable one. Remember though, though you can't really "block" the user, unless you are using a lower level language such as C#.net or Java.
- Check this out for information on it: http://w3schools.com/htmldom/prop_nav_appname.asp You would have to do an if or switch statement in JavaScript sort of like this: <script type="text/javascript"> if (navigator.appName == "Netscape") { document.write("Your browser is not supported."); } else { document.write("Your code here...."); } </script>
- The best way to do this is in your server script - that way users cannot bypass your javascript by switching javascript off. The environment variable HTTP_USER_AGENT can be used in your script to detect the browser and you can return whatever page you like with no need for redirection. This is example PHP of browser detection: <?php if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Gecko') ) { if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Netscape') ) { $browser = 'Netscape (Gecko/Netscape)'; } else if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Firefox') ) { $browser = 'Mozilla Firefox (Gecko/Firefox)'; } else { $browser = 'Mozilla (Gecko/Mozilla)'; } } else if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'Opera') ) { $browser = 'Opera (MSIE/Opera/Compatible)'; } else { $browser = 'Internet Explorer (MSIE/Compatible)'; } } else { $browser = 'Others browsers'; } echo $browser; ?>
Powered by Yahoo! Answers