Windows 10 reached EOS (end of support) on October 14, 2025. For more information, see this article.

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

How to add a custom js file?

  • 8 个回答
  • 3 人有此问题
  • 2 次查看
  • 最后回复者为 Nitish

more options

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

more options

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

more options

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?

more options

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

more options

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于修改

more options

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

more options

Do we have to create /pref folder and mozilla.cfg files?

more options

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.

more options

After creating /pref folder, where should I put my JS code?