/    Sign up×
Community /Pin to ProfileBookmark

Toolbar button to change background colour of web pages

I want to create a toolbar for FireFox consisting of one button to change the background colour of the currently viewed webpage. I am building the toolbar in XUL, this XUL file houses the buttons, and then references a JavaScript file which holds the functions.

At present I have a button “Background Colour”, when I click on it, there is a drop down menu of 4choices, when you click on any of these I have set up a popup message to say “Code for Changing Background Colour goes here”.

This is the XUL code

[CODE]
<button type=”menu” label=”Background Colour”>
<menupopup>
<menuitem label=”White” oncommand=”BGColour(event)”/>
<menuitem label=”Black” oncommand=”BGColour(event)”/>
<menuitem label=”Cream” oncommand=”BGColour(event)”/>
<menuitem label=”Blue” oncommand=”BGColour(event)”/>
</menupopup>
</button>
[/CODE]

This is the javascript:

[CODE]
function BGColour(event)
{
alert(“Code for changing background colour goes here”);
}
[/CODE]

How would I change the background colour of the webpage at hand? Would it be a case of placing a .css file over the top of the viewed webpage? If so how would you do this? If not, any ideas?

Thanks!!

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 03.2008 — document.body.style.backgroundColor='yellow';
Copy linkTweet thisAlerts:
@twinkle_twinkleauthorApr 08.2008 — Thanking you!!?

is there a website i can view that would provide me with a list of these functions? As i'd like to add functionality to my toolbar to change the text colour / font and size also.

ta!
Copy linkTweet thisAlerts:
@twinkle_twinkleauthorApr 12.2008 — whenever i insert the following code into my js file referenced by the toolbar, and install the toolbar none of the toolbar functions accessed by any of the buttons work, any ideas what's going wrong? or what i could try?? i can't see what i'm doing wrong ?

Thanks guys!


function BGColour(event)

{

var currentDocument = getBrowser().getBrowserForTab( getBrowser ).selectedTab ).contentDocument;

currentDocument.body.style.backgroundColor = "magenta";

BrowserReload();

}
Copy linkTweet thisAlerts:
@twinkle_twinkleauthorApr 12.2008 — there was a ( missing from theabove code, ive put this in place, so now the other buttons work but this button doesnt seem to do anything:

[CODE]
function BGColour(event)
{
var currentDocument = getBrowser().getBrowserForTab( getBrowser ).selectedTab ().contentDocument;
currentDocument.body.style.backgroundColor = "magenta";
BrowserReload();
}
[/CODE]
Copy linkTweet thisAlerts:
@twinkle_twinkleauthorApr 13.2008 — Fixed ? thanks! that function now for the functions to change text color, font and size ?
×

Success!

Help @twinkle_twinkle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...