2

I want to set the homepage and new tab URL on Firefox and Chrome. When the user clicks on a button on my webpage, it will automatically change the browser homepage.

  1. When we go to about:config on the Firefox, we have all of configuration to customize. There is a preference name browser.newtab.url - I have to set/change this value to my custom URL.

Is it possible to change this string value by JavaScript or through a URL the user clicks on?

  1. I have to change Chrome new tab URL by JavaScript or through a URL the user clicks.

I don't know if this is possible or not.

If you know a way to change these things, then please tell.

Makyen
  • 31,849
  • 12
  • 86
  • 121
Robin Hossain
  • 711
  • 9
  • 12
  • this is covered and easily searchable already in s.o. see the linked dup of which there are many other similar results in a simple google search. – Zig Mandel Sep 15 '15 at 16:39
  • While the linked "duplicate" page does describe how, or how it is not possible to, change the home page URL from a web page, this question asks how to 1) change the home page, and 2) how to change the new tab URL. The tags also imply that the question is from the point of view of a Firefox Add-on, or a Chrome extension (not from a page script). However, the text implies that the context is a page script. Thus, it is not clear to me that this is a duplicate, but it may be. – Makyen Sep 15 '15 at 18:46
  • @RobinHossain, please clarify the question to be specific as to the context in which you are asking. Are you asking about a page script/URL that will perform the functions you are asking about (a page script/URL that could be included on any website), or are you asking how to do this from a Firefox Add-on or Chrome extension that the user has specifically installed? – Makyen Sep 15 '15 at 18:49
  • yes @Makyen I am asking about a page script/url that will perform the functions...it will change the browser default homepage url to custom one. open script/url - next time when user open new tab - it always redirect to custom homepage. – Robin Hossain Sep 16 '15 at 04:41
  • Note `browser.newtab.url` has been [removed from Firefox as of Firefox 41](http://www.ghacks.net/2015/06/28/mozilla-removes-option-to-change-new-tab-page-from-firefox/) ([bugzilla](https://bugzilla.mozilla.org/show_bug.cgi?id=1118285)). It is now necessary to use a Firefox add-on to obtain this functionality (e.g. [New Tab Override (browser.newtab.url replacement)](https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/)). – Makyen Sep 16 '15 at 16:11

1 Answers1

0

Partial answer (for Firefox, not using a page script) may be:

var about_config = require('sdk/preferences/service');
about_config.set('browser.startup.homepage', 'http://www.stackoverflow.com');
about_config.set('browser.newtab.url',       'http://www.stackoverflow.com');

This will cause about:home and about:newtab to redirect to your URL. Yet it won't affect about:blank. Actually, when you manually type about:home or about:newtab (instead of opening a new tab or clicking home page button) the override in about:config still doesn't seem to trigger.

require('sdk/preferences/service') exposes the same settings that are accessible by typing about:config in the address bar.

However there seems to exist a requirement to revert the changes later:

// By AMO policy global preferences must be changed back to their original

var { when: unload } = require('sdk/system/unload');
unload( function() {
  about_config.set('browser.startup.homepage', oldValue);
  about_config.set('browser.newtab.url',       oldValue);
});

If you wish to follow that requirement, then you can get old values using .get() instead of .set().

Sagi
  • 578
  • 1
  • 4
  • 13
  • 1
    FYI: `browser.newtab.url` has been [removed from Firefox as of Firefox 41](http://www.ghacks.net/2015/06/28/mozilla-removes-option-to-change-new-tab-page-from-firefox/) ([bugzilla](https://bugzilla.mozilla.org/show_bug.cgi?id=1118285)). It is now necessary to use a Firefox add-on to obtain this functionality (e.g. [New Tab Override (browser.newtab.url replacement)](https://addons.mozilla.org/en-US/firefox/addon/new-tab-override/)). – Makyen Sep 16 '15 at 16:13