Skip to content

Instantly share code, notes, and snippets.

@pwlin
Created April 18, 2010 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwlin/370188 to your computer and use it in GitHub Desktop.
Save pwlin/370188 to your computer and use it in GitHub Desktop.
// Opening window/tab helper library for Mozilla
var $window = {
open_in_new_tab: function(url){
getBrowser().selectedTab = getBrowser().addTab(url);
},
open_in_same_tab: function(url){
top.content.document.location = url;
},
open_as_popup: function(url){
var mypopup = window.open(url,'popuppage','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=700,height=400,left=30,top=30');
mypopup.focus();
},
focus: function(obj){
obj.focus();
},
click : function(aEvent,url){
if (aEvent.button == 2){
this.open_as_popup(url);
}
else if ((aEvent.ctrlKey) || (aEvent.button == 1) || (aEvent.metaKey)){
this.open_in_new_tab(url);
}
else {
this.open_in_same_tab(url);
this.focus(window._content);
}
}
}
Usage:
<toolbarbutton id="myid" label="my button" class="toolbarbutton-1" onclick="$window.click(event,'http://localhost/');" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment