Browser-Specific Code for IE and Netscape

Browser-Specific Code for IE and Netscape
If you are designing a website, it is critical that you understand the differences between IE - Internet Explorer - and Netscape, and code for both.

The first thing you need to do is figure out what type of browser your visitor is using. You would do that with this code:

Dim SvrVar
Set SvrVar = Request.ServerVariables
BrowserName = SvrVar("HTTP_USER_AGENT")
OpSys = SvrVar("HTTP_UA_OS")
Set SvrVar = Nothing

Now you know exactly what browser and what operating system your user is using. Next, you would set up a separate style sheet for each browser. Different browsers use different stylesheet commands - and different operating systems use different fonts. Here would be a way to handle the four main combinations:

'SHOW STYLESHEET FOR MATCHING SYSTEM'
if InStr(BrowserName, "MSIE") > 0 and InStr(BrowserName, "Win") > 0 then
Response.Write ""
end if
if InStr(BrowserName, "MSIE") > 0 and InStr(BrowserName, "Win") = 0 then
Response.Write ""
end if
if InStr(BrowserName, "MSIE") = 0 and InStr(BrowserName, "Win") > 0 then
Response.Write ""
end if
if InStr(BrowserName, "MSIE") = 0 and InStr(BrowserName, "Win") = 0 then
Response.Write ""
end if

That takes care of the basics. Let's now get on to the actual page construction. One big difference between IE and Netscape is that IE uses body parameters of "topmargin" and "leftmargin", while Netscape goes with "marginheight" and "marginwidth". So your code to write your body statement could look like this:

if InStr(BrowserName, "MSIE") > 0 then
Response.Write ""
else
Response.Write ""
end if

You would use this same logic all through your code, making sure to write it appropriately based on what browser and operating system your user was working with. Yes, much of HTML is understood by all browsers, but you want your website to look at perfect as possible in all conditions. It is your responsibility as a developer to test your code on IE and Netscape, on PCs and Macs, to understand what the world sees when they view your website!




RSS
Related Articles
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map





Content copyright © 2023 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.