MozillaZine


Open Webpage with Custom Buttons

Talk about add-ons and extension development.
CrazyForStarWar

User avatar
 
Posts: 51
Joined: November 9th, 2004, 6:11 pm

Post Posted July 31st, 2006, 6:48 pm

I've already asked this in a topic but got no response. I'd just like to know what code to use for the Custom Buttons extension that will allow the button to open a webpage in the current tab (you can use anything as an example) with left click, and open the same page in a new tab (unfocused) with middle click. Please reply. Thanks!

Old Michael Buckley
 
Posts: 0
Joined: December 31st, 1969, 5:00 pm

Post Posted July 31st, 2006, 11:50 pm

This is what I use in one of my extensions

Code: Select all
   if(event.button == 0) {
   loadURI('https://addons.mozilla.org/firefox/themes/');
   }
   else if(event.button == 1) {
   getBrowser().addTab('https://addons.mozilla.org/firefox/themes/');
   }


If you did want the new tab to be focused on you would use

Code: Select all
   if(event.button == 0) {
   loadURI('https://addons.mozilla.org/firefox/themes/');
   }
   else if(event.button == 1) {
   firefoxTe = getBrowser().addTab('https://addons.mozilla.org/firefox/themes/'); getBrowser().selectedTab = firefoxTe;
   }


I have not tested this is custom buttons and do not know if it works or not. But I think it should.
New [url=http://forums.mozillazine.org/profile.php?mode=viewprofile&u=299802:3o1quhg8]Michael Buckley[/url:3o1quhg8] account as old one was lost.

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted August 1st, 2006, 8:04 am


In code tab:
Code: Select all
openUILink(URL, event, false, true)


In initialization code tab:
Code: Select all
this.setAttribute("onclick", "checkForMiddleClick(this, event)");


However, there is a bug in <code>checkForMiddleClick</code> function on Firefox 1.5.0.*, so use this to init code tab:
Code: Select all
this.checkForMiddleClick = function(aNode, aEvent) {
  if(aEvent.button == 1) {
    var fn = new Function("event", aNode.getAttribute("oncommand"));
    fn.call(aNode, aEvent);
    closeMenus(aEvent.target);
  }
}

this.setAttribute("onclick", "this.checkForMiddleClick(this, event)");

My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

CrazyForStarWar

User avatar
 
Posts: 51
Joined: November 9th, 2004, 6:11 pm

Post Posted August 1st, 2006, 10:49 am

Michael, your's didn't work but thanks anyways.

Thanks Zool, your's worked fine. But is there anyway to make that tab unfocused?

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted August 1st, 2006, 11:54 am


Change the <code>browser.tabs.loadInBackground</code> value to "true" in about:config

My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest