How to add a custom js file?
I want to add a custom .js file that is to be run when Firefox starts. This file also contains code other than adding preferences. Many internet sources suggest solutions that are related to adding preferences. What changes do I need to make and where do I put this .js file?
Version: Firefox 32
所有回复 (8)
Hello Nitish, probably you are referring to a user.js file !
You have to put it in your Profile folder.
What are the changes you are try to make to the default firefox ?
Read carefully the above article and if you have any questions definitely someone from the forum have the answer. :-)
thank you
This was my doubt. The article that you have referred to says "A user.js file is an alternative method of modifying preferences". Can it be used for changes other than preferences also?
You can create preferences also in a user.js file.
see for more information : A brief guide to Mozilla preferences
see also an excellent add-on which you can can create custom Firefox configurations : Mike Kaply's CCK2 Wizard
thanks again
The user.js file is read each time Firefox is started and initializes preferences to the value specified in this file, so preferences set via user.js can only be changed temporarily for the current session because you get the values as specified in the user.js files on the next start. So only use it to reinitialize prefs to a known value that you may have changed during a session (e.g. search engines) and otherwise rename or remove the user.js file after it has done its work to initialize prefs.
You can use a mozilla.cfg file in the Firefox program folder to lock prefs or specify new (default) values. This file is run as a JavaScript file with full chrome permissions and thus can be used to run any JavaScript code (so be cautious what you place in it).
Place a local-settings.js file in the defaults\pref folder where also the channel-prefs.js file is located to specify using mozilla.cfg.
pref("general.config.filename", "mozilla.cfg");
pref("general.config.obscure_value", 0);
These functions can be used in the mozilla.cfg file for setting prefs:
defaultPref(); // set new default value pref(); // set pref, allow changes in current session lockPref(); // lock pref, disallow changes
See:
由cor-el于
@ideato, this is what I put in user.js file currently
var changes = function(){ document.body.style.overflowY = "hidden"; } document.addEventListener("load", changes);
I want to make overflowY to be hidden on all webpages(actually only body element) that I load. Presently, this is the only change I have done in my profile folder and this is not working. Any ideas on how this can be done?
Do we have to create /pref folder and mozilla.cfg files?
You can't place JavaScript code in the user.js file because this file is interpreted and only allow user_pref() calls.
If the pref folder isn't there there you should create it, but the defaults\pref (or defaults/pref) should be there and contain the channel-prefs.js file that sets the update channel (this file is never touched by an update).
You will have to create the mozilla.cfg file in the main Firefox program folder and make sure the the first line is a comment line that starts with // as this line is skipped.
After creating /pref folder, where should I put my JS code?