Reputation: 13
I have no idea what I'm missing here. I want to make a javascript, that responds to screen resolution, but I can't get it to work. Any input?
<SCRIPT LANGUAGE="javascript">
if (screen.width <= 479)
{document.write("Less tgab 479");}
if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}
if (screen.width <= 768 && <= 989)
{document.write("Between 768 and 989")}
if (screen.width >= 990)
{document.write("Above 990")}
</SCRIPT>
All help are appreciated.
Upvotes: 1
Views: 87
Reputation: 62027
Your shorthand for the ands doesn't work, you have to explicitly write each condition out. Also you got the first condition backwards
from this:
if (screen.width <= 480 && <= 767)
{document.write("Between 480 and 767")}
to this:
if (screen.width >= 480 && screen.width < 768)
{document.write("Between 480 and 767")}
Upvotes: 0
Reputation: 777
This should work
if (screen.width <= 479) {document.write("Less tgab 479");}
if (screen.width >= 480 && screen.width <= 767) {document.write("Between 480 and 767")}
if (screen.width >= 768 && screen.width <= 989) {document.write("Between 768 and 989")}
if (screen.width >= 990) {document.write("Above 990")}
The problem was you had wrong conditions in the second and third if
screen.width >= 480 && screen.width<= 767
screen.width >= 768 && screen.width<= 989
Upvotes: 1