সহায়তা খুঁজুন

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.

আরও জানুন

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

  • 5 উত্তরসমূহ
  • 1 এই সমস্যাটি আছে
  • 10 দেখুন
  • শেষ জবাব দ্বারা Jose Canciani

more options

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

প্রেক্ষাপটে এই উত্তরটি পড়ুন। 👍 0

All Replies (5)

more options

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.

more options

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.

more options

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

more options

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...

more options

চয়ন করা সমাধান

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