Spot the error

Tannin

0
Joined
Jan 15, 2002
Messages
4,448
Location
Huon Valley, Tasmania
Website
www.redhill.net.au
What's wrong with this code?

It works fine in IE 5.0, IE 6., and Mozilla. In Opera 7.23 I get the text and it's functional but no stylesheet - just plain vanilla black and white text. In Opera 6.05, I just get a blank page.

OK, OK, mayube the correct question is "what's wrong with Opera", but I suspect that the real answer is that I have some bad code somewhere and that IE and Mozilla are coveringup my mistakes for me. Be nice to nail it.



<head>
<script>
<!--
var width1=1025
var width2=1281
if (screen.width<width1) {
document.write ('<link rel="stylesheet" type="text/css" href="t1024.css">\n');}
else if (screen.width<width2) { document.write ('<link rel="stylesheet" type="text/css" href="t1280.css">\n');}
else { document.write ('<link rel="stylesheet" type="text/css" href="t1600.css">\n');}
--!>
</script>
</head>
<body>

Assorted text and stuff goes here .....
 
OK, I got it. Opera hates the HTML comment thingie <!--

Take out the comment markers (which are really rather pointless anyway, as I'm not bothering to try to make this readable in a non-CSS capabe browser anyway) and it works. Bizarre!

Is there some special magic to comments in Opera?
 
Oh yeah, and when you signal to open comments within the script tag, use:

Code:
//--

It is the double forward slashes that are important for comments in script tags, the stuff that follows on the same line can be anything.
 
By the way, if this same script will be used on several html pages, why not create a link to an external js file. That way all you need to include is:

Code:
<script src="xxx.js"></script>

When you make changes to that one js file, all of the pages will automatically be able to use it without requiring you to edit every page with this code.
 
Cool! Thankyou Buck. I can't wait to get home and try it out.

Within a day or two, I'll upload a sample page from my mammoth trip report with pictures thingie, using that code, which I can then apply to the 50-odd pages of it when they are all finished. (Betterthan half done so far.)
 
Tannin said:
Cool! Thankyou Buck. I can't wait to get home and try it out.

Within a day or two, I'll upload a sample page from my mammoth trip report with pictures thingie, using that code, which I can then apply to the 50-odd pages of it when they are all finished. (Betterthan half done so far.)

betterthan is not a word Tannin. You are going crazy with the combined words now, aren't you?
 
Yeah. Sorry about that Tim. Ever since Tea'sbeengone there seemstohavebeen a certainlackoflunacy aroundtheplace. Bless her little hairy feet, if Tea was here, I'm sure she would say that lunacy is like lightning: it's always around and just takes the shortest path to earth. Seems that, as the most intelligent ape left standing, that is now me.

Damnit! I was perfectly happy beingthegrumpyone.
 
timwhit said:
Tannin said:
Cool! Thankyou Buck. I can't wait to get home and try it out.

Within a day or two, I'll upload a sample page from my mammoth trip report with pictures thingie, using that code, which I can then apply to the 50-odd pages of it when they are all finished. (Betterthan half done so far.)

betterthan is not a word Tannin. You are going crazy with the combined words now, aren't you?
Neither is Thankyou. :lol:
 
Oh --- but wait! We are on Google now. Thanks to your contribution, there are now 12,700,001 hits!

PS to Buck: I like the include: much neater. A progress report and perhaps a sample in a couple of days.

Err ... dare I say "thank(?)you"?
 
Back
Top