1

I know how to set the default homepage for Google Chrome and Internet Explorer, but i searched Google and Stackoverflow for possible answers on how to achieve this with Mozilla Firefox but with no chances.

I'm wondering if there is a possible way to programmatically set a default Start page for Mozilla Firefox browser using C# ( but i can't figure out where does Firefox store it's homepage.. )

How can i programatically set/change default homepage for Mozilla Firefox ?

Thanyou in advance.

Rafik Bari
  • 4,867
  • 18
  • 73
  • 123

4 Answers4

1

What you will need to do is programmatically edit the prefs.js file in the user profile for Firefox.

It can be found in the directory C:\Users\ [USERNAME]\AppData\Roaming\Mozilla\Firefox\Profiles\ [Some Subfolder]

You will need to add or edit the line that looks like: user_pref("browser.startup.homepage", "www.google.com");

emd
  • 1,173
  • 9
  • 21
1

I know question was answered but maybe next coders can be need a source.

 string firefox = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla\\Firefox\\Profiles");
        if (Directory.Exists(firefox))
        {
            FileInfo di = new DirectoryInfo(firefox).GetDirectories()[0].GetFiles("prefs.js")[0];
            StreamReader sr = di.OpenText();
            RichTextBox rb = new RichTextBox();
            rb.Text = sr.ReadToEnd();
            sr.Close();
            string[] s = rb.Lines;
            for (int i = 0; i < rb.Lines.Length; i++)
            {
                if (rb.Lines[i].StartsWith("user_pref(\"browser.startup.homepage\""))
                {
                    s[i] = "user_pref(\"browser.startup.homepage\", \"http:\\\\www.somesite.com\");";
                    break;
                }
            }
            File.Delete(di.FullName);
            File.WriteAllLines(di.FullName, s);
        }

This will change firefox homepage. I hope I can helped someone

Enes Can Çetiner
  • 71
  • 1
  • 3
  • 11
  • I know that this is an old answer, but I've tried it and it looks like it doesn't work. Any hints ? – Cajuu' Apr 01 '15 at 13:47
  • Worked for me. Have you tried stepping through the code, maybe your Firefox prefs are in a different location. – MikeS159 Oct 04 '16 at 14:14
0

You might want to use console commands to find the file wich holds your homepage URL

First thing I would try: set your homepage to something non existent to prevent hitting cookies with the same url like www.testfirstnamelastname.com

Then go to your Terminal/commandline and type

grep -lr "www.testfirstnamelastname.com" *

If you want to search admin protected directories add sudo before the command..

hope this helps you out

dennis
  • 2,000
  • 18
  • 26
  • I am working on windows, not linux :) is there a possible way to search for a string within file under windows 7 ? – Rafik Bari Apr 06 '12 at 12:55
  • Simple: download this program http://www.wingrep.com/ it will help you find reg exp and strings everywhere (this saves alot of time) – dennis Apr 06 '12 at 13:05
0

Check the below link

http://chiragrdarji.wordpress.com/2007/03/26/add-to-favorite-in-firefox-and-ie/

No need for any code behind.

Ravi Vanapalli
  • 9,805
  • 3
  • 33
  • 43