2011-01-28 49 views
2

HI,安装插件后在Firefox中打开我的页面

我试图在安装后第一次重新启动firefox后打开我的主页。

为此,我在加载页面上添加事件处理程序,并检查第一次执行该事件的时间。

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

但我的问题是如何在firefox开始时在新选项卡中打开页面。我用

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

但是,在新窗口打开页面,甚至可能会在Internet Explorer中打开。

那么有没有什么办法可以在打开的同一个窗口的新标签中打开页面。

感谢 BHAVIK GOYAL

回答

2

我管理使用偏好,而不是创建文件等

内/默认/喜好做类似的事情/default.js:

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

然后为附加在主JS文件中:

// 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"));  
} 

唯一的问题是Firefox不重置通过扩展存储的偏好扩展卸载后。

+0

THanks NudeCanalTroll,但它适用于所有操作系统,我的意思是Mac,Linux和Windows? – 2011-01-29 06:18:26

1

我得到了答案。我们可以添加gbrowser.open("http://www.xyz.com/")在新标签页中打开及本声明有新的功能是通过调用其定义为跟随其他事件处理函数loadedoverlay要执行:

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

这个函数的调用有通过添加行的代码,如下面的Load事件函数添加: -

var appcontent = document.getElementById("appcontent"); // browser 
if(appcontent) 
    appcontent.addEventListener("DOMContentLoaded", loadedOverlay, true); 
+0

请注意,创建一个文件来跟踪这是过度杀伤;设置偏好要容易得多。否则,我会指出,这不是你应该如何处理文件名。 – Neil 2011-01-28 23:27:05