Browse DevX
Sign up for e-mail newsletters from DevX


Essential JavaScript: 8 Cross-Browser Solutions-2 : Page 2

There's a core set of problems that every JavaScript developer will run across sooner or later. This article shows you how to deal with eight of the most common situations.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Sniffing the Browser
Problem 1: How do I determine which browser a person is using?

Believe it or not, determining the browser isn't all that important. What is important is what objects the browser supports. There are plenty of browser sniffers out there that use the navigator object to determine the exact browser manufacturer and version. The problem with all of those navigator-based sniffers is that if the browser maker changes the settings the sniffer will fail. Instead, use object detection to make your scripts forward compatible:

   if (document.layers){
      //Netscape 4 specific code
   if (document.getElementById){
      //Netscape 6 specific code
   if (document.all){
      //IE4+ specific code

Even though IE5 supports the getElementById() function, if you are careful with your code, you can force IE5 to run only the appropriate code (see the next topic Writing Cross-Browser Scripts).

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date