Dynamically changing the page background

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Dynamically changing the page background

Post by drayarms »

Hello, I thought this was a very simple problem. I'm trying to set the various pages of a site with individual background themes. I want the users to define pick their own them color or image which would be stored in a database, and then dynamically applied via Ajax during runtime. To test the concept, I started off with this simple script which should set the background color of every page to white, except for 3 pages which I expect to retain the default background theme as defined in my css file(Default is a color gradient). Unfortunately, these 3 pages also displayed a white bg, and not the default gradient theme. Any ideas why? Here is the code.

Code: Select all



		<script type='text/javascript'> //Assign page background dynamically


			$(document).ready(function() {


				if((window.location.href !== 'http://url.com/signup.php')||(window.location.href !== 'http://url.com/register.php')||(window.location.href !== 'http://url.com/login.php')){


					$('body').css('background','#fff');

				}
			
  

			});			



		</script>


User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Dynamically changing the page background

Post by Celauran »

You're using or where you should be using and. Any page only has one URL, so at least two of the three conditions are bound to be true.
drayarms
Forum Contributor
Posts: 134
Joined: Fri Dec 31, 2010 5:11 pm

Re: Dynamically changing the page background

Post by drayarms »

@celauran, you are right. How could I miss that? Thanks.
Post Reply