Hi, I have never learnt javascript because it is easy to add snippets of code to my web pages. Now I am trying to learn, but my first attempt is not working.
Can anyone explain what I have done wrong?
Code:
resCheck.js
window.onload = resCheck;
function resCheck(){
var change =
if(screen.width/screen.height>1.4){
if(screen.width<1100){'http://www.website.co.uk/styles/wideS.css';}else
if(screen.width>=1100){'http://www.website.co.uk/styles/wideN.css';}else
if(screen.width>1600){'http://www.website.co.uk/styles/wideH.css';}
}else{
if(screen.width<1024){'http://www.website.co.uk/styles/normS.css';}else
if(screen.width>=1024&&screen.width<'1600'){'http://www.website.co.uk/styles/normN.css';}else
if(screen.width>=1600){'http://www.website.co.uk/styles/normH.css';}
document.getElementById('style').href=(change);
}
Errors? IE says it on the bottom left, Chrome requires you to hit ctrl+shift+I, Firefox I recommend adding the Firebug addon. There has to be something if it doesn't work. If there are no errors then its in the way in included the file, or something in the html. Let us know.
Okay, my error comes up when you are trying to set the var change. Try revamping the code so you aren't setting the var directly. You can see the error if you go here, its a free syntax checker.
function resCheck(){
var screenWidth = screen.width;
var screenHeight = screen.height;
var ratio = screenWidth / screenHeight;
if(ratio>1.4){ratio=wide;}
var change =
if(ratio='wide'){
I tried to do this, but ...
Uncaught SyntaxError: Unexpected token if line 40
Bookmarks