Update: I’ve put up a new howto with new instructions for Firefox3.5 and 3.6 ans the new userChrome1.1.
When Firefox 3 started its beta program, I decided to give it a shot. Since then, I never came back to Firefox 2. Firefox 3 was faster, stronger, better 😉 than its predecessor. However, there was one point where Firefox 3 has some problems : extensions. Many extensions where not working anymore. While this is now fixed with many extensions updated, Firefox 3 includes the new « places » functionnality that replaces bookmarks, history etc… And this new functionality irremediately broke my custom userchrome.js for opening bookmarks in tabs (without midlle clicking, that is). Since I only open bookmarks in tabs, with was a little troublesome for me, but, being the only grip I had, I decided to live with it. Until today, where I finally figured out how to write a new « magic line » in my userchrome.js, thanks partly to tab mix, partly to google, and partly to my brain :).
So, here is the complete howto:
- How to open search box in a new tab. This one is easy, just open about:config (type about:config in url bar) and filter with « search ». Look for
browser.search.openintab
and put its value to « true ». Voilà, new tabs for search box (a must if you ask me, plus combo if you have the right search engines – i.e. not only google). - How to open urls in a new tab. This one as well bookmarks requires userchrome.js. This is a very small extension that allows javascripts snippets to be executed the same way you have userChrome.css styles added to a page. I used version 0.8, but I think 0.7 version works as well. So go on and download it, then create a userChrome.js file in your chrome folder (inside your user profile folder, look at the Chrome folder article and Profile folder article on MozillaZine if you need help). From this point, you can fill it directly with the code provided here or use the sub-script/overlay loader as in my own userchrome (allows the loading of other scripts). If you want, you can download my own userChrome.js directly and put it in the chrome folder. Now you can paste this code inside a .uc.js file in the same folder or inside userChrome.js:
eval("BrowserLoadURL = " + BrowserLoadURL.toString().replace("e;", "$& if ((gBrowser.currentURI.spec != 'about:blank' || gBrowser.webProgress.isLoadingDocument)) { var tab = gBrowser.addTab(); gBrowser.selectedTab = tab; }"));
This will open a new tab for url typed in url bar. You will have to restart your broswer to have the new behaviour.
- How to open bookmarks in new tab. This was the most difficult task since very few information is available on the internet. The key was using PlacesUIUtils for accessing functionnality. The code is:
eval("PlacesUIUtils.openNodeIn = " + PlacesUIUtils.openNodeIn.toString().replace("openUILinkIn(aNode.uri, aWhere);","if ((gBrowser.currentURI.spec != 'about:blank' || gBrowser.webProgress.isLoadingDocument) && (aNode.uri.indexOf('javascript:') == -1)) {openUILinkIn(aNode.uri, 'tab');}else{openUILinkIn(aNode.uri, aWhere);}"));
You will have to restart your broswer to have the new behaviour.
The whole OpenInTabs.uc.js is available if you want both functionality, just drop it into the same folder as userChrome.js. As a bonus, you can download ChromaTabs for Firefox 3 if you like colored tabs. If you have any question or remark, please leave a comment. Have fun with firefox 3 !
Update: If you want to have open in tab functionality for only some tabs, here are the shortcuts :
- Url and search : Press Alt+Enter to open in a new tab. With url you can combine Alt with the classic Ctrl(end in .com), Shift(in .net) and Ctrl+Shift(in .org). That is, google +Ctrl+Shift+Alt = www.google.org in a new tab.
- Bookmarks : Ctrl+Click on a bookmark opens it in a new tab.
Update: Now bookmarklets are supported.
Update 2009/03/01: For Firefox 3.1, the BrowserLoadUrl doesn’t exist anymore. There is new way to have correct behaviour:
(function() {
urlbar = document.getElementById("urlbar");
eval("urlbar.handleCommand = " + urlbar.handleCommand.toString().replace("&& aTriggeringEvent.altKey","&& !aTriggeringEvent.altKey"));
})();
This switch the Alt behaviour. If you want to open in the same tab, hold Tab, else, it will open automagically in a new tab (this is so easy that I’m asking myself why they did not include it as userpref). Have fun !
Re: How to open urls in a new tab.
Thanks for the great instructions! I had googled this topic fr a loooong time, until I came to your site.
Now, I discovered by chance that ALT-return also opens the urls in a new tab. But I guess you wanted this to always happen.
tks again
Christian
Hi Christian,
Thanks you for your comment ! I searched google for quite a bit also 🙂
I did not know the alt thing, this is great when I’m on another computer.
I’ll include it in the tutorial.
Thanks !
it doesn’t work in RC2 that the code open urls in a new tab , what problem?
the code open bookmarks in new tab is ok, but it can’t work in sidebar
and there is a code for open history in new tab?
Hi jojo115,
I never encountered any problem opening history, however you are right, this code doesn’t work from sidebar. I’m not sure of what is causing it, I’ll try to have a look when I have some time.
Also, you could try to upgrade in latest Firefox when it comes out and see if it works.
Thanks for your support !
I followed these instructions for my Firefox 3.0 RC3 installation.
I copied your userChrome.js to my profiles folder, then I copied your OpenInTabs.uc.js into the same folder.
But it didn’t work. URLs that I entered into the address bar did not open in new tabs.
I then copied your eval() function directly into the userChrome.js file, but that also didn’t work.
In FF2, I used the TabMixPlus extension to configure all of my tab behaviours. But TMP hasn’t yet been released for FF3.
So I really would like to get your nifty JavaScript solution to work.
Do you have any ideas what the problem might be? Does your code work for FF3 RC3?
Hi Ron,
Please make sure this is your Chrome folder inside your Profile, not directly your profile folder.
On windows, this is usually:
C:\Documents and Settings\\Application Data\Mozilla\Firefox\Profiles\\chrome (by default it contains two files : userChrome-example.css and userContent-example.css)
On linux, this is:
~/.mozilla/firefox//chrome
If this was already the correct location, you can try to put this line in your userChrome.js:
alert(« test »)
and restart firefox. If this works & not the evals(), this need further investigation.
Also a last note, did you verify that the userChrome.js extesion is correctly installed on your Firefox (i.e. shows up in your extension window).
they should have provided options for opening tabs for url and bkmarks in firefox 3.
Script works fine. just a gripe, i’v got all these javascripts as bookmarks (like darken/change color of current page, etc).now these open in new tabs instead of opening in curent tab.surely there’d b a workaround for this. it’d b appreciated if u’d look into it (wd post updates if I come up with a solution)
Hi sree,
I could not more agree with you, an option should be available. As for javascript as bookmarks, could you please provide me a sample code of such a bookmark so I can look into ?
Thanks !
Does not seem to work for Mac OS X, FF 3. The alert(”test”) failed. Tried a new uc.js (downloaded the suggested), and also add to existing userChrome.js.
Folder is here on my Mac: ~/Library/Application Support/Firefox/Profiles//chrome
Hi x2b4,
First of all, thanks for spending your time trying to help others with the same needs as you.
I guess I need your particular help too. I am following your instructions as a cooker follows their recipe, which is even harder for me since I am not hacker material nor english is my native language.
I seem to have managed the first two modifications very well. But I don’t understand what you mean with « The key was using PlacesUIUtils for accessing functionnality ». I will probably sound stupid and I probably am, but I tried to find this PlacesUIUtils as a complement, as a file, but failed in both attempts. I even tried to Google it but… Where, what or who is this PlacesUIUtils? What shall I do then?
Thanks for your help!
Marcos
here is a sample javascript as bookmark
*********
javascript:(alert(« hello »))();
*********
the script goes in the location field of a bookmark. this works in address bar also. u could put any javascript in.
javascript:(/*javascript*/)();
identify and prevent bokkmarks/url’s starting with ‘javascript:’ from loading in new tabs.ma b
It works with when I open a bookmark from the bookmark menu, but it doesn’t work when I open bookmark from the sidebar menu 🙁
Did I do something wrong?
Is it possible to make this work also for sidebar menu?
adfs: Are you sure the userchrome.js extension works on Mac ? I don’t have one myself, but I could ask a friend to test it.
Marcos Hayun:
Thank you for your comment. The PlaceUtils is not something you should do. In your case, the best thing is just to download OpenInTabs.uc.js (here: http://www.x2b4.com/wp-content/uploads/2008/06/OpenInTabs.uc.js) and put it in the chrome folder. Good luck !
sree & zix : These are limitations of my current method. I will try to work around both problems next weekend. I think there is a solution, I just don’t know what it is yet. Stay tuned.
Dear x2b4,
I did it, I swear I did! Still doesn’t work for the favorites, neither on the toolbar or it’s menu. Works ok only for the google search bar.
I even copied it and saved on both chrome folders, one in the root Firefox folder (C:\Arquivos de programas\Firefox\chrome) and the other one under « C:\Arquivos de programas\Firefox\defaults\profile\chrome »
By the way, « Arquivos de programas » means Program files, in portuguese.
Maybe I should delete the userChrome.js which is in the same place?
And before you ask, yes, I restarted Firefox after doing that. No good, whatever.
🙁
Thank you once again,
Marcos
Hi Marcos,
Both chrome folder you tried are incorrect I think. The good chrome folder should be inside something like
C:\Documents and Settings\[Windows login/user name]\Application Data\Mozilla\Firefox\Profiles\[profile folder]\chrome
with of course Documents and Settings translated into Portuguese (if necessary). There are many chrome folders, but this one should work. Copy both userChrome.js and OpenInTabs.uc.js in this same place. Gook luck again 😉
If you already tried this, forgive me 🙂
Yessssssssss!!!!!!
Now it works! Thank you very much!
Since I was a Netcaptor orphan user, this was the only let-down that I was facing about Firefox.
Hope I will be able to help you the same way in the future! Yet, that’s hard to believe…
Once again, thank you!
Marcos
Hi x2b4!
Many thanks for posting this stuff.
The good: I have installed the extension, some of the scripts from other sites are working and I’m very happy with them (« status bar in menu bar », « DragNGo »).
The bad: Unfortunately so far neither of your two scripts work for me. I’m using the first official release of Firefox 3.
With the bookmarks script, it’s the same glitch that was pointed out before: new tab when called from menu, same tab when called from sidebar. For me however, it’s almost always the sidebar. I know this is doable since Tab Mix Plus used to do it. It would be great if you could figure out a way to do it, too.
Stuff called from the address bar so far also hasn’t opened in new tabs with your method, but I’m now thinking this might be an incompatibility with one of my other extensions and I will do some exerpimenting.
I’m definitely staying tuned to see if you can come up with any fix to the bookmarks issue.
For now, I’m back Tab Mix Plus. A working version for FF3 can be found here:
http://tmp.garyr.net/forum/viewtopic.php?t=7031
Thanks to x2b4’s brain!
This is a perfect solution for people that don’t want to install Tab Mix Plus or where Tab Mix Plus comes in conflict/has issues with other Firefox add-ons.
I use the Tab Kit add-on for grouping and coloring related tabs. Some settings in Tab Kit and Tab Mix Plus comes in conflict , but with this “How to” I could remove Tab Mix Plus and have my tabs the way I like them.
Thank you very much!
-Neolamprologus
Neolamprologus,
Thanks for this comment 🙂 ! This gives me the motivation to continue :p.
After the crappy choice of removing some about:config entries from Firefox, I was disappointed. But this sounds a lot more promising than the heavy Tab Mix Plus thingy… I used to have Tabbrowser preferences installed in FF2, but it doesn’t have any official site anymore…
Thanks for the post !
Thank you so much. The instructions were so easy to follow. I really wanted this functionality. I didn’t want to have to press Alt+Enter every time I want the URL to open in a new window. I wish Tab Mix Plus worked with latest version of FF3.0.1 but this is a great solution!!! Many thanks again!!!!
Ranbow, Roger, you’re welcome 🙂
Thanks x2b4 it worked for me as well. Unfortunately the instructions did not come to me as clearly as others, but after a while I was able to get it to work. I do however have a comment about the tabs selected. Once I select a link from either the location bar or bookmarks my tab opens but my page does not switch to it immediately. I need to click on it. If you select tools/options/tabs/option to switch to it immediately is selected but it obviously does not work.
Not the end of the world just an FYI.
thanks again,
knackll
@knackll : it works fine for me and it focuses on the new tab when launching from URLbar or from bookmarks. I’m using a lot of extensions so it may be a inherited behavior…
@x2b4 : the « dropping in the same folder… » trick does not work, I have to put every piece of code in my main userChrome.js to have it working, but since I don’t use a lot of .uc.js tricks it’s not a big deal !
Rainbow, It does switch to the new tab immediately when opened fron the URLbar. But does not open from the bookmarks or personnel toolbar. I’ve tried some other options but just can’t see to get it to work. If I change the code around I can get it to switch to it immediately but it wont populate with the selection (meaning when bookmark is clicked the tab opens & switches to it but, the page becomes blank).
I’ll play with it some more. Maybe, I’ll figure it out.
Thanks,
X2b4,
EXCELLENT work!! Thank you for this.
However, to chime in with sree – there are bookmarklets (javascript in bookmarks) that need to work in the same tab. I do not know Chrome but is there a way to use a modifier (eg. Ctl + click) to *disable* your open-in-new-tab functionality on a case by case basis? Sounds like it should be possible.
An example of a common one is the « Share in Friendfeed » bookmarklet. This needs to operate on material in the same tab, even though it is is stored in a bookmark.
http://friendfeed.com/share/bookmarklet
Please help!
Mark
There are two ways I invoke bookmarklets, so I can’t use item #2 or #3, because they force a new tab. The two ways of invoking a bookmarklet.
1) from a bookmark, okay with item #2 not with item #3
2) from a keyword shortcut invoking a bookmarlet, no good with either item.
The script to open new tab from URL does not work anymore in 3.1B1 since BrowserLoadURL is no longer defined.
Ronin, thank you for your input. I was unaware of this problem since I’ve not tested 3.1b1 yet. I’ll give it a shot this week end. Do you know if there is any replacement for the BrowserLoadURL function ? Thanks !
Not that I know of, but when I asked alice0775 about it he said « Modify « handleCommand » method in tabbrowser.xml ».
Now, I am not familiar with JS so am not sure if I will be able to do it. Let me know if you are able to figure it out.
Not sure if you know alice0775.. he is a userchrome.js expert… look at this.. http://space.geocities.jp/alice0775/index2.html ; but I couldn’t find any way to reach him directly.
I posted a comment earlier today, but looks like it didn’t go through.. I asked about a workaround to alice0775 (http://space.geocities.jp/alice0775/index2.html) on a forum and this is what he had to say:
« Modify « handleCommand » method in tabbrowser.xml »
Frankly, given the limitation of my technical knowledge, am not sure of what can be done with this. Maybe you have a clue.
Hi ronin,
There is a workaround, but it involves fiddling with the browser.jar file. I’ll look tomorrow at this tabbrower.xml thing…
Hi, x2b4
Thanks a lot for these tips and for taking the time to help others who need the same features in Firefox.
I’ve followed your instructions and I have achieved the desired behaviour (new tabs open from bookmarks and search bar, I don’t need new tabs from url bar).
Unfortunately, it looks like installing the userChrome.js add-on and the required javascript file to make your modifications work has taken away the possibility of opening bookmarks from the Library. I can open bookmarks from the bookmarks menu (new tab) or from the sidebar (same tab, but I don’t care much since I don’t use the sidebar a lot). But when I try to open a Bookmark from the Library, nothing happens. Neither double clicking nor right clicking and choosing « Open in new tab » work. It’s as if I hadn’t click anything. It’s really a shame because I find your solution very, very useful. Do you think it can be solved? Can you verify the same behaviour?
Thanks again
Hi city_zen, opening bookmarks in the library does work for me in the library with both double clicking and right clicking. This is at home with version 3.0.4. Which version are you using ? I’ll give it a shot at work, I’m with ff3.1. Thank you for your support !
Hi again x2b4,
I’m happy to report that my problem has (somewhat mysteriously) been solved. I disabled a number of add-ons, but that didn’t make a difference, so I re-enabled them. Then I deleted the userchrome.js file and let the userchrome add-on recreate it. I proceeded to edit it, adding your snippet, and restarted Firefox. Everything works now! 🙂
I’m using FF 3.0.4 with the (es-AR) locale, by the way
Thanks for your reply and your willingness to help
A little update 🙂
It stopped working again, but this time it was because th userchrome,js file had become corrupted (I have no idea how it happened). Anyway, I recreated it and the only way that I could make it work again was by choosing to paste the snippet above the default line (« if (location != « chrome://browser/content/browser.xul ») throw « stop »; »), so that it only works in the main browser window. Maybe that’s what caused to start working before. It’d be ideal if I could make it work also in the Library window, but it’s good enough as it is now. Right now, when I double click on an item in the Library window, it opens it in the same (active) tab. Of course, in the main Firefox windows, I get a new tab for bookmarks, which is the main behavior that I wanted to achieve.
Hi,
As an old maxthon users I had many problems on tab using. This article has solved many of this problem. I’ve two question:
1- Is this extension and this hack safe?
2- When I enter an url at current tab, Firefox successfuly focused the new tab with new url. But url that I’ve entered at old tab is not clearing. Is there a way clearing url from old tab.
Thank you for your topic and sory my poor English.
Tayfun
Hi Tayfun, the extension and the hack are totally safe. We’re only using standard instructions to tell firefox to open a tab. This would be the same code if you used the Alt modifier.
As for the url not clearing thing, I experienced the same thing. My solution is to refresh the page with the original url if you need it.
Thank you for your comment-back. For clearing; I’ve put your code that is in item #2 to my userChrome.js. Url wasn’t cleared. While I’ve read your comment I put your userChrome.js file to my Chrome folder but still it is not clearing. Which one is your solution?
Thats a good code update… but I believe it needs to be modified a bit to ensure:
– That if there is a blank tab (about:blank), that tab should be used instead of opening a new tab
– If its a Javascript Bookmarklet, again the operation should happen on current tab and not on a new tab.
I am sure there would be a few other modifications that can be made.
Hi again…
That post was so helpfull back when I google helped me find it, I was wondering if there’s any way it can be adapted to Firefox 3.5…
The open-new-tab-from-awesome-bar would really be a blessing (as I replaced my search bar with keywords). I’m not quite the Javascript coder I should be and I couldn’t get google to give me the answer…
Hi Rainbow.
You can use the firefox 3.1 tricks with firefox 3.5, but maybe it would be more helpful if I created a new tutorial. I’ll do it asap and post in the comments.
All right, it works… I had to delete my subscript loader and add the code right in my userChrome.js (for some unknown reason…) but it works !
Thanks a lot that was quick and helpfull !
I’ll try to fix my subscriptloader and post a description of the problem and the solution…
Ok it’s fixed now…
I used zoolcar9’s subScriptLoader [@ http://zoolcar9.lhukie.net/mozilla/userChromeJS/ ] and deleted a few lines so that no Error is throw-ed at start-up
Thanks again !