views:

219

answers:

3

I am developing an Firefox extension. How can all the links on a webpage to be opened in a new tab?

A: 

Press Ctrl while clicking on the link on Windows. Use cmd on OSX.

powtac
I'm pretty sure that Firefox extensions can't press keys on the keyboard (unless hooked into something like a USB robot!)
David Dorward
or press the scroll button on your mouse
Jason
It's not that he wants to do it as a user - he wants code in his extension that does it as part of the app...
Mark Mayo
Maybe he don't know that this is a build in feature...
powtac
Thank you all but u guys are not hitting the chord... you know what i mean... like in greasemonkey u can open a given link on any webpage (not a website hosted by me) any general one... So in greasemonkey i can do the following:link.addEventListener('click',function(e){ e.stopPropagation(); e.preventDefault(); GM_openInTab(this.href);},false);Would anyone know a code equivalent to this for extension developement?
fftoolbar
Ok, I think you are very close! Just check out this pages: http://tools.w3clubs.com/ext/ http://ted.mielczarek.org/code/mozilla/extensiondev/
powtac
+2  A: 

That's usually a configurable option in Firefox to handle new links, so they may override your extension with that.

However...

The code

<a href="http://www.example.com/"&gt; Example Website</a>

will allow you to click the appearing words [Example Website], and the link will open in the current window.

The code

<a href="http://www.example.com/" target="_blank"> Example Website</a>

Opens the link in a new window/tab.

The only mildly dodgy thing is that target is now apparently deprecated by the W3C, which means that it's generally up to the browser ( and the user's preferences) as to how (or even if) it is handled. But for people who have their preferences set accordingly - in Firefox - that should work.

Mark Mayo
+1  A: 

I found what I was after. I wanted gbrowser.addtab(this.href).

fftoolbar