![]() |
|
|
netscape internet explorer dynamic content moving elements < cross browser > resources |
Before "true" cross-browser DHTML becomes available (in other words, when NS and IE comes to their senses), cross-browser DHTML basically means using various scripting techniques you picked during those JavaScript years to sniff out which browser the user is using, and execute the code intended for that browser. In this lesson, I'll first illustrate a way of creating a "cross-browser" layer, then show you a scripting technique I recently learned that allows you to easily sniff out the browser type of the surfer.
Creating a "cross-browser" layer <div id="crosslayer" style="position:absolute"></div> NS 4 treats the above div exactly the same as it would with a layer. Like any other layer, to access it , we would first go go through the document object, then the layer's id: document.crosslayer In IE 4, we would simply use the div's id: crosslayer I found that in NS, specifying a layer this way, while convenient in terms of cross-browser compatibility, has one major draw back. Such a layer doesn't always behave the way a normal layer should, and can sometimes actually crash the browser. Just be prepared to expect the unexpected! Browser sniffing, object detectionUp until recently, whenever I wished to determine the browser type of my surfers, I would use the navigator object, like most JavaScript programmers would. The below illustrates using this object to sniff out both NS 4 and IE 4:
var ns4= (navigator.appName== "Netscape"&&navigator.appVersion>=4)
Personally, I hate using the navigator object- its so complicated to use (just look at the above mess!). Well, I have good news to bring to you. There is actually a lot quicker way to sniff out various browsers, and its called object detection.
if (document.images)
Translating the above into English, it reads: "If the browser supports the images object (which only NS 3+ and IE 4+ do), alert a message.
if (document.layers)
if (document.all)
if (document.layers||document.all) Now you never have to return to the messy navigator object to do your browser sniffings!
DHTML resources
Dynamic Drive DHTML examples This tutorial is written and contributed by David Gardner.
Help promote this site <a href="http://www.weballey.net/">WEBalley</a> |
![]() |
|