This site will have limited functionality while we undergo maintenance to improve your experience. If an article doesn't solve your issue and you want to ask a question, we have our support community waiting to help you at @FirefoxSupport on Twitter and/r/firefox on Reddit.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

I want to open external links in already opened tab (web 2.0 apps hash links)

  • 5 பதிலளிப்புகள்
  • 1 இந்த பிரச்சனை உள்ளது
  • 22 views
  • Last reply by Jose Canciani

I have a web 2.0 app, where the app is intelligence enough to detect hash changes (# or #!), and update appropriately.

An email comes to my inbox, with a link to the app (ex: myapp.com/#Case/2013). I already have an open tab in this domain, let's say: myapp.com/#Dashboard.

So I want Firefox to be clever enough to reuse the tab and just update the url, and the app will do the rest.

Is this possible out of the box, do I need an extension? It seems more and more the web is filling with these type of apps, and opening links in new windows/tabs all the time is useless, since webapps usually has their own tab management or similar way of navigating its content.

Thanks! Jose

I have a web 2.0 app, where the app is intelligence enough to detect hash changes (# or #!), and update appropriately. An email comes to my inbox, with a link to the app (ex: myapp.com/#Case/2013). I already have an open tab in this domain, let's say: myapp.com/#Dashboard. So I want Firefox to be clever enough to reuse the tab and just update the url, and the app will do the rest. Is this possible out of the box, do I need an extension? It seems more and more the web is filling with these type of apps, and opening links in new windows/tabs all the time is useless, since webapps usually has their own tab management or similar way of navigating its content. Thanks! Jose

தீர்வு தேர்ந்தெடுக்கப்பட்டது

After searching a bit more, I decided to build my own extension, and after a couple of hours digging stack overflow and the sdk doc, I built what I needed. Here's the code:

var tabs = require("sdk/tabs"); var pageMod = require("sdk/page-mod"); pageMod.PageMod({

   contentScriptWhen: 'start', // This says not to wait until the page is ready
   include: ['*.yourdomain.com'],
   onAttach: function(worker) {
       var thisTabUrl = worker.tab.url.split('#');
       var isAlreadyOpened = null;
       for (var tab in tabs) {
           if (tabs[tab].id != tabs.activeTab.id) {
               var thatTabUrl = tabs[tab].url.split('#', 1);
               if (thatTabUrl[0] === thisTabUrl[0]) {
                   worker.tab.close();
                   tabs[tab].activate();
                   tabs[tab].url = thisTabUrl.join('#');
                   return;
               }
           }
       }
   }

});

Regards, Jose Canciani

Read this answer in context 👍 0

All Replies (5)

This is in a stand-alone mail client? Firefox's built-in options for external links are:

(1) First tab in a new window

(2) New tab in the latest window active in Firefox (default)

(3) Replace contents of last active tab in Firefox

While (3) is close to what you want, it's not intelligent enough to match up with the actual tab you would want to update.

(If you are clicking a link in webmail, your options are similar, but the default is to replace the current page unless the link is coded to target a new window, in which case the default is to open a new tab in the current window.)

I suspect you will need an extension.

One way that applications re-use their own window or tab is to re-use a specified "target". While typically links are launched in a new tab using the special target name "_blank", if the link uses a target name that Firefox already has opened (such as "myappwindow") then in theory the link should target that window. In order for this to work, though, the existing page you want to replace needs to have been opened either from a link with that target or the JavaScript window.open() method with that target. To my knowledge, there's no way to assign that target name retroactively.

It occurs to me that if you are implementing this for customers and they have unsaved work in the tab you're replacing, you may need to implement some kind of autosave to avoid angry support calls.

Thanks for the answer. I mentioned email client just to try to say "any other program opening a link in the default browser firefox" :) In my case, it was Thunderbird.

I guess I will need an extension, I'll leave the problem open some time to see if someone knows about one that do this. I looked but did not find one.

Does the use of target in a link reload the tab content? Or does it just change the url when we are using just a different hash? This could indeed solve at least partially the problem when opening links from inside firefox, although we wil need to modify our app to use target. Anyway, it seems mail clients strip the target part of the anchor tag, so it doesn't help much :(

Thanks, Jose

Hi aerotux, when you target a named tab, the new URL loads in place of the current content. I haven't tested what happens when the only change is the hash...

தீர்வு தேர்ந்தெடுக்கப்பட்டது

After searching a bit more, I decided to build my own extension, and after a couple of hours digging stack overflow and the sdk doc, I built what I needed. Here's the code:

var tabs = require("sdk/tabs"); var pageMod = require("sdk/page-mod"); pageMod.PageMod({

   contentScriptWhen: 'start', // This says not to wait until the page is ready
   include: ['*.yourdomain.com'],
   onAttach: function(worker) {
       var thisTabUrl = worker.tab.url.split('#');
       var isAlreadyOpened = null;
       for (var tab in tabs) {
           if (tabs[tab].id != tabs.activeTab.id) {
               var thatTabUrl = tabs[tab].url.split('#', 1);
               if (thatTabUrl[0] === thisTabUrl[0]) {
                   worker.tab.close();
                   tabs[tab].activate();
                   tabs[tab].url = thisTabUrl.join('#');
                   return;
               }
           }
       }
   }

});

Regards, Jose Canciani