Jump to content

Dynamically changing the page background


drayarms

Recommended Posts

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.

 

 



	<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>


Link to comment
Share on other sites

In the if statement

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'))

i would replace the or (||) with (&&). Im sure this is your problem!

 

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')){

 

Hope that helps.

Link to comment
Share on other sites

@jayjay, well i have to use the OR operator and not the AND since I want the condition to be true if either one of those 3 pages is displayed. Anyway, I solved the problem by defining two different css classes, then using the removeClass() function and addClass() to assign the various classes to the pages I want.  Thanks though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.