PDA

View Full Version : NN/MSIE Code compatability (if else statements)


bacterozoid
10-19-2002, 02:57 AM
Alright, here is my script:


<script language="javascript">
if (screen.width == '800')
{
document.write ("")
}
else {
document.write ("ERROR MESSAGE")
}
</script>


I wrote that myself, lol, some easy basic stuff that I can do. (Yet I can edit and troubleshoot really advanced scripts...go figure) Well, I know that you are going to look at that and think 'amature,' so go right ahead, lol. What I need to know is why it won't read properly in Netscape. No matter what resolution I use it does not display the 'else' statement error; it displays whatever I put up there in the 'if' statement, which will be nothing at all.

I don't think it's the fact of having a blank 'if' statement, which I had to use because I don't know any simpler way to eliminate a possibility, lol, if you know what I mean...

So anyways, why won't it work in NN and how do I fix it? Thanks


To see 'er in action Click here (Princeton Bands) (http://www.geocities.com/jon_zie/band/homepage.htm)

I just made a whole new front page for the actual site which someone else runs, but up under the 'Princeton Bands' where there is a <hr> is where your error message should appear.

beetle
10-19-2002, 06:23 AM
Why don't you

alert(screen.width);

And see what it's receiving in NN?

brothercake
10-19-2002, 08:05 AM
Originally posted by bacterozoid
if (screen.width == '800')


You only want this condition to run if the screen width is *exactly* 800? Perhaps you mean

if (screen.width >= 800)

Note also that 800 is a number - but you've used '800' which is a string, which might be why it doesn't return conrectly in netscape

bacterozoid
10-19-2002, 04:27 PM
Beetle, good idea. I shall try that. Though I think the whole number/string thing might be my problem. I remember a little bit of that when I was going over mathamatical functions. Also as for the >= thing, I didn't know what else to use really. I am not entirely famaliar with those things. I'll try a few things out and let you know. Thanks!

Also, I want a condition to run if the screen res. is not 800 x 600, but I didn't know any other way than what I had to achieve that. I did find out the unequal thing, though (!=) which I may or may not use, we shall see.

bacterozoid
10-19-2002, 04:44 PM
Well I'll be...

It works fine, but Netscape, being the evil that it is, doesn't realize that the computer has changed until you restart...go figure. Thanks for the other help though, I can use that to help me out with making the best of the script. *sigh* stupid Netscape...

Bosko
10-19-2002, 04:48 PM
What the hell is NN?Netscape 7?

What about window.screen.availHeight and window.screen.availWidth??

bacterozoid
10-19-2002, 04:52 PM
Yeah, NN=Netscape Navigator...though I only have 6.2, never use it. But I spose it might help to get the latest version.

beetle
10-19-2002, 07:04 PM
bacteroziod, those 'things' you refere to all called 'operators'. Here are some of the most commonly used ones (but there are more...)logical Operators
< Less than
> Greater than
<= Less than or equal
>= Greater than or equal
== Equality
!= Inequality
=== Identical or 'strict equality'
!== Nonidentical or 'strict inequality'
&& logigal AND
|| logical OR
! logical NOT

Assignment Operators
= Assignment
OP= Compound assignment (OP is any of the computational operators below in blue)

Computational Operators
++ Unary increment
-- Unary decrement
+ Addition (and string concatenation)
- Subtraction
* Multiplication
/ Division
% Modulo division (finds remainder)

bacterozoid
10-19-2002, 07:11 PM
Lol, I realize that. My big Javascript book says:

JavaScript Comparison Operators

==
!=
>
>=
<
<=

And then what they do. (JavaScript Bible - 4th ed.)

I used the is not equal to in my script which got rid of the else and just gave me the if statemtent, which simplified it somewhat. But thanks for the reference, I might actually run into using these some day.