2

HI,

My am trying to open my home page after the firefox restarts for the first time after installation.

For this i am adding the event handler on load page and checks where this event is executed for the first time or not.

window.addEventListener("load", initializeOverlay, false);

But my problem is how to open the page in new tab when the firefox get started. I use

`window.open("https://www.xyz.com/");`

but that opens the page in new window that might even be open in internet explorer.

So is there any way to open the page in new tab in same window which is going to be open.

Thanks BHAVIK GOYAL

Bhavik Goyal
  • 2,786
  • 6
  • 23
  • 42

2 Answers2

2

I manage to do something similar using preferences, rather than creating files, etc.

Inside of /defaults/preferences/default.js:

pref("extensions.extension_name.just_installed", true);
pref("extensions.extension_name.post_install_url", "http://www.google.com");

Then inside the main JS file for the add-on:

// Retrieve the preferences.
var prefs;
prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.extension_name.");
prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);

// If we just installed, open the post-install page and update the preferences.
var just_installed = prefs.getBoolPref("just_installed");
var post_install_url = prefs.getCharPref("post_install_url");
if (just_installed) {
  prefs.setBoolPref("just_installed", false);
  gBrowser.selectedTab = gBrowser.addTab(prefs.getCharPref("post_install_url"));    
}

Only problem is Firefox doesn't reset the preferences saved by an extension after that extension is uninstalled.

NudeCanalTroll
  • 2,266
  • 2
  • 19
  • 43
1

I got the answer. We can add the gbrowser.open("http://www.xyz.com/") to open in new tab and this statement has to be executed in new function that is by calling the other event handler function loadedoverlay which is defined as follow:

function loadedOverlay() {
try{
 var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
 file.initWithPath(Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path+"\\initialstart.txt");
 if ( file.exists() == true )
{   
}
else
{
file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
var Website="http://www.emailstationery.com/";
gBrowser.addTab(Website);//This is for new Tab
}
} catch(e) {}
}

The call to this function has to be add in the load event function by adding the code of lines as below:-

var appcontent = document.getElementById("appcontent");   // browser 
if(appcontent) 
    appcontent.addEventListener("DOMContentLoaded", loadedOverlay, true); 
Bhavik Goyal
  • 2,786
  • 6
  • 23
  • 42
  • Note that creating a file to track this is overkill; setting a preference is much easier. Otherwise I would point out that this isn't how you should work with file names. – Neil Jan 28 '11 at 23:27