Hey guys, hopefully someone can help me out here. I thought what I was trying to do was going to be simple, but unfortunately for me at least that hasn’t been the case. I usually write everything in VB 2008, but what I’m doing requires it to be in Javascript. The setup I have is a little too complex to explain, but let’s just say that I’m VERY restricted on how I have to go about this. I only have access to the Javascript source that is placed in the header of all pages and the universal css file. I can’t manipulate pages individually. The code I have is below and what I’m trying to do is read the pathname of the url and change the background image of header div based on that pathname. I only have 6 pages so I just created a switch statement to change the image, but it’s not executing any of my cases and even when I tested it outside the switch it doesn’t change the background image in the stylesheet.
Javascript————————————–
window.onload = changeHeader();
function changeHeader() {
var site = location.pathname;
switch (site)
{
case “/link1.aspx” :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x2.jpg’) no-repeat”;
break;
case “/link2.aspx” :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x3.jpg’) no-repeat”;
break;
case “/link3.aspx” :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x4.jpg’) no-repeat”;
break;
case “/link4.aspx” :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x5.jpg’) no-repeat”;
break;
case “/link5.aspx” :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x6.jpg’) no-repeat”;
break;
default :
document.getElementById(“header”).style.background=”background-image: url(‘/data/header_x1.jpg’) no-repeat”;
break;
}
}
DIV Tag————————————
<div id=”header”>
…content
</div>
CSS STYLE———————————-
#header {
background: url(‘/data/header_x1.jpg’) no-repeat;
width:800px;
height:120px;
…
}
Thanks for any help!