homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
cross browser development
coding for mass appeal
mossimo




msg:596493
 4:56 am on Apr 17, 2003 (gmt 0)

Hello people,

I am using java to detect browser and load the right CSS, currently "IE" or "NN v5+". Works great unless you have navigator 4.01 i get a JavaScript error "unable to load style sheet" yet my script has an option for older browsers. May be navigator 4.01 uses an older version of java? How do you handle cross browser development? Here's the script.

<SCRIPT language="JavaScript" type="text/JavaScript">
<!--
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
//load ie friendly stylesheet
document.write('<link rel="stylesheet" href="ie Main.css" type="text/css">')
}
else
{
if ((parseFloat(navigator.appVersion)) >= 5 )
{
// if ns version is great than or equal to 5 (6) load this stylesheet
document.write('<link rel="stylesheet" href="ns Main.css" type="text/css">')
} else {
//if you have a really ancient browser ;-) (ie. NS 4.7 or earlier) load this

stylesheet
document.write('<link rel="stylesheet" href="ns Main.css" type="text/css">')
}
}
//-->
</SCRIPT>


Thanks

[edited by: Woz at 5:41 am (utc) on April 17, 2003]
[edit reason] no URLs please [/edit]

 

ShawnR




msg:596494
 5:13 am on Apr 17, 2003 (gmt 0)

Welcome to WebmasterWorld!

I have a few suggestions:
===========================
1. Remove the spaces in your filenames. Newer browser substitute the %20 code for the space before requesting the document from the server, whereas older browsers don't.

2. Check your code gets to
document.write('<link rel="stylesheet" href="ns Main.css" type="text/css">')
(By putting a debug alert statement in. If there are errors before it, NN4.7 gives up, whereas newer browsers are more forgiving.

3. Remove your url from the post. ;)

A couple of things to note:
===========================
1.
"... May be navigator 4.01 uses an older version of java..."
Java and Javascript share part of their name, but otherwise are completely different things.

2. There are ways to comment out stuff from style sheets for NN4.7, so that you have a single style sheet. Browse through the posts in the CSS forum for more info.

3. You are loading the same stylesheet for NN6+ and NN4. Was that your intention?

Shawn

BlobFisk




msg:596495
 9:47 am on Apr 17, 2003 (gmt 0)

Welcome [webmasterworld.com] to WebmasterWorld, mossimo!

In your script decleration you use both the language and type decleration - you should only use the type="text/javascript" decleration - the language attribute is deprecated:


<script type="text/javascript">

ShawnR




msg:596496
 10:36 am on Apr 17, 2003 (gmt 0)

"...you should only use the type="text/javascript" decleration - the language attribute is deprecated...

I guess there will always be different opinions, so here is mine: Don't drop the 'language' attribute; retain both! The problem you trying to fix is compatibility with NN4.01 which I think came out way before Netscape (or Microsoft) concerned itself with being compatible with any standards, and way before the 'type' attribute was introduced.

If removing the spaces (or converting them to %20's) doesn't help, look here: [webmasterworld.com...]

Shawn

rainborick




msg:596497
 2:00 pm on Apr 17, 2003 (gmt 0)

While I'm a Netscape fan, I'm solidly on the bandwagon that promotes letting NS4 finally die. That is, unless you have a compelling reason to continue supporting it, I recommend not putting any substantial effort into doing so. It was superceded in early 2000 by NS6 and subsequently by NS7 which is very standards-compliant. I know most people are still on dial-up and the 24MB download is a drag, but there comes a time when all of us have to bite the upgrade bullet and this is how we get the last stragglers to upgrade from Windows v3.1, Win95, and so on: making the reasons to upgrade outweigh the costs of doing so. Post a blurb that explains that NS4 can't handle the features you want to provide for your users, that upgrading is free, that the current version has a built-in pop-up blocker, and that all of their old settings and bookmarks will migrate during the upgrade automatically.

That said, if you need to specifically detect NS4, the easiest and best way is:

if (document.layers) { NS4 = true; }

Only NS v4.x supported the document.layers property, so you can special case that family of browser. Otherwise, of course, its best to detect features rather than try to parse the browser strings. I know that's not always possible, but by and large it handles most programming situations.

g1smd




msg:596498
 6:17 pm on Apr 17, 2003 (gmt 0)

One more suggestion:

Write all filenames all in lower case, and write HTML tags and attributes in lower case. This is recommended in HTML 4.01, and then it becomes a requirement once you move on to XHTML.

mossimo




msg:596499
 1:52 am on Apr 18, 2003 (gmt 0)

Thanks for all the suggestions

I have decided my JavaScript CSS loader is junk at least for my intended use (by the way when I said java I meant JavaScript) my bad.

Any one know of a good style loader that can handle 4 CSS.

for example:

Navigator 4
IE 4
IE 5+
Navigator 6+

grahamstewart




msg:596500
 2:29 am on Apr 18, 2003 (gmt 0)

If you can use php then it would be much easier.
Your loader.php file could look something like..

[pre]
<?php
header( 'Content-Type: text/css');
$browToFileMap = array (
'IE' => 'ie_style.css',
'Netscape' => 'ns_style.css',
'Opera' => 'opera_style.css',
);
$defaultFile = 'ie_style.css';
$foundMatch = FALSE;
$browser = get_browser();

foreach( $browserToFile as $name => $file ) {
if ( preg_match('/'.$name.'/i', $browser['browser']) ) {
$foundMatch = TRUE;
$fp = fopen( $file, 'r' );
$fpassthru( $fp );
}
}
if (!$foundMatch ) {
$fp = fopen( $file, 'r' );
$fpassthru( $fp );
}
?>
[/pre]

then you can call it from your html like this...

<link rel="stylesheet" href="loader.php" type="text/css">

That should work (but its just off the top of my head so check the syntax :)).

If you need to expand this to deal with particular versions of products then you could look at the $browser['version'] variable as well.

ShawnR




msg:596501
 3:22 pm on Apr 18, 2003 (gmt 0)

Hi all

Blobfisk pointed out to me that my comment (message #4) could be misconstrued as advocating retaining both lanuage and type attribute for all web development, so I'd like to clarify: My comment ("retain both") is only in relation to mossimo's original question, requesting help getting his code compatible with NN4.01. For general web development, Blobfisk has a valid point.

Shawn

mossimo




msg:596502
 8:49 pm on Apr 18, 2003 (gmt 0)

Thanks grahamstewart

I got that .php loader to work, much cleaner than JavaScript. Problem solved.

Still having problems trying to code NN4x, Browser News web site lists NN4x users as less than 1.3% and shrinking. My target audience is fairly hip so Iím thinking of just saying forget it and let old Netscape users DIE. How concerned should I be about this.

Let me know and thanks
mossimo

grahamstewart




msg:596503
 2:32 am on Apr 19, 2003 (gmt 0)

Absolutely, I am a big advocate of this.

Change happens constantly in the IT industry. If people are still browsing with software that was release in 1997 the they must expect a few problems.

I find it a little bizarre that everyone is obsessed with NN4. Does everyone also code their pages to work on IE4, Opera 3 and Mosaic 3?

Personally I write my pages to follow a current standard (usually HTML4.01 Strict and CSS1) and to work well on the current generation of browsers.

I don't see the point of bashing your head off a wall to deal with obsolete software.

mossimo




msg:596504
 4:00 am on Apr 19, 2003 (gmt 0)

My sentiments exactly grahamstewart

I agree I always try to code for HTML4.01 Strict (or transitional) and CSS1. We all know a page wont look the same in all browsers and small anomalies are acceptable but I canít accept a page I sweated on be mangled by older browsers even if there users are a tiny minority.

By the way this is my first large contract job with a client that will be making a profit of the site, witch i hope explains my obsession with the older browsers.

thanks, mossimo

Hobgoblin




msg:596505
 7:47 pm on Apr 21, 2003 (gmt 0)

@mossimo:

NN4 users are dwindling, but NN6 and 7 users are on the rise. I use NN 7.02 and I love it - NN7 is much easier to code for as well - better login IMNERHO :)

I design quite a bit of flash too, and NN handles flash links better than IE (IE doesn't support a referring document property of the link was from a link in a Flash plugin on an HTML page).

Bottom line - it's always good business to make everyone happy and able to see your website the same way. Those who use obsolete browsers (4th generation and below) are slowly getting used to pages not looking right - most will soon make like a belt and buckle :)

branmh




msg:596506
 12:10 pm on Nov 7, 2004 (gmt 0)

using this below how to add linux browser:


<?php
header( 'Content-Type: text/css');
$browToFileMap = array (
'IE' => 'ie_style.css',
'Netscape' => 'ns_style.css',
'Opera' => 'opera_style.css',
);
$defaultFile = 'ie_style.css';
$foundMatch = FALSE;
$browser = get_browser();

foreach( $browserToFile as $name => $file ) {
if ( preg_match('/'.$name.'/i', $browser['browser']) ) {
$foundMatch = TRUE;
$fp = fopen( $file, 'r' );
$fpassthru( $fp );
}
}
if (!$foundMatch ) {
$fp = fopen( $file, 'r' );
$fpassthru( $fp );
}
?>

[edited by: tedster at 4:34 am (utc) on Nov. 11, 2004]
[edit reason] splice to the original thread [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved