Focus tab or window
Solution 1:
The following appears to work in IE8 and FF13:
<script type="text/javascript">
// Stupid script to force focus to an existing tab when the link is clicked.
// And yes, we do need to open it twice.
function openHelp(a) {
var tab = window.open(a.href, a.target);
tab.close();
tab = window.open(a.href, a.target);
return false;
}
</script>
<a href="help.html" target="help" onclick="return openHelp(this);">Help</a>
Solution 2:
The only solution I see, is to force the popup in a new window, since there doesn't seem to be a way to focus another tab. This solution also requires you to change the default Javascript security settings in Tools > Options > Content tab
and click on the Advanced
button next to Enable Javascript
checkbox and check the middle box to allow focusing windows.
To force the use of a window rather than a tab, use win = window.open("http://www.google.com", "test" ,"modal=yes");
and then call win.focus();
whenever you feel like it.
EDIT: Actually forgot to mention the fact that this is FF only.
Solution 3:
See Mozilla's documentation: https://developer.mozilla.org/en/Code_snippets/Tabbed_browser.
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserEnumerator = wm.getEnumerator("navigator:browser");
// Check each browser instance
while (browserEnumerator.hasMoreElements()) {
var browserWin = browserEnumerator.getNext();
var tabbrowser = browserWin.gBrowser;
// Check each tab of this browser instance
var numTabs = tabbrowser.browsers.length;
for (var index = 0; index < numTabs; index++) {
var currentBrowser = tabbrowser.getBrowserAtIndex(index);
if (/*some logic*/) {
// For an example
tabbrowser.selectedTab = tabbrowser.tabContainer.childNodes[index];
// Focus *this* browser-window
browserWin.focus();
break;
}
}
Here is an easier event-driven approach - https://developer.mozilla.org/En/Listening_to_events_on_all_tabs.