mardi 31 mars 2015

Multiple if statement returning css value depending on URL

The script works but their seems to be a bug causing the first and last if statement to implement the style no matter what page it is on. The middle if statement does not display.


I have also tried a break and return after each if statement but that completely brakes the script and does not display anything on the page.



window.onload = function()
{
var ThisStyle = "background-color: #4C4C4C; color: #fff; -webkit-border-top-right-radius: 15px; -webkit-border-bottom-right-radius: 15px; -moz-border-radius-topright: 15px; -moz-border-radius-bottomright: 15px; border-top-right-radius: 15px; border-bottom-right-radius: 15px;"

if (document.URL.indexOf("index.php"))
{
document.getElementById("home-nav").style.cssText = ThisStyle;
}

else if (document.URL.indexOf("about.php"))
{
document.getElementById("about-nav").style.cssText = ThisStyle;
}

else (document.URL.indexOf("products.php"))
{
document.getElementById("products-nav").style.cssText = ThisStyle;
}
}


Anyone have any idea what I am doing wrong?


Aucun commentaire:

Enregistrer un commentaire