RSS2.0

I moved to Debiprasad.net. Now I am blogging there, so please visit Debiprasad.net and keep me reading. love, Debiprasad

Ask questions related to online shopping in India

Where to buy online in India?

wheretobuyonline.in

Change background color of any webpage using JavaScript

Have you ever seen any webpage with similar background color and text color? So how do you feel while reading those texts? I feel difficulty in such cases. But one simple JavaScript will work great to change the background color as you wish and you can read the text easily.

Now please read this (click here to see the working solution): document.bgColor is deprecated : How to change the background color of any web page using JavaScript --- Please click here to see the working solution.

javascript:document.bgColor='white'; void(0);

What you have to do is copy above code, pase it in the address bar of your browser and hit enter. And you will find the background color of thet page has changed.

Here I have given the color as white. You can use any color as you wish. You can also use both name of the colors and hexadecimal color code.

This works both in Internet Explorer and Mozilla Firefox. Before this code I was using only javascript:document.bgColor='white'; But while using this code, this goes to another page and displays the value which you have given for background color. So, I have to hit back to read the previous page. This works in Mozilla Firefox only and in IE, it did not work, as IE unable to catch the change done by external javascript. Thanks to Tanima for find out this problem.
-----------------
One more thing, if you are using IE (Internet Explorer), I recommend you to use Mozilla Firefox.

Change background color of any webpage using JavaScriptSocialTwist Tell-a-Friend TwitThis Reading: Change background color of any webpage using JavaScriptPost Link to Twitter

2 comments:

Justin said...

As you said, the method you are using is deprecated. The better way to do it is to use:

javascript:void(document.body.style.backgroundColor="#123456")

It is cross-browser and meets current standards.

Debiprasad said...

Thanks Justin.

The method I have posted here is deprecated as this is an old post. I have given the update on this post.

My Shared Items in Google Reader

My Blogroll

Followers

Want to see/show anything here? Contact me :)