I've been trying to open a "popup" [1] without it taking the focus automatically.
I tried to blur it, from the opener or from the popup itself unsuccessfully. I also looked for pop-under but didn't find anything relevant on Google about both topic.
I'm using Firefox. (Well… Palemoon 24.7.1 for x64 actually)
My goal is to be able to open a bunch of tabs (with middle click for instance) and having them closing on their own a bit later.
To do so in Firefox, and afaik, you MUST use a popup (right?). But everytime I open a new tab (with middle click) it focuses on it which is very annoying.
[1] Or anything else that could match my expectations.
EDIT: NOTE: This is for personnal use. :)
First the easy one: For mouse-middle-click: In Tools->Options on the "Tabs" tab, there is an option "When I open a link in a new tab, switch to it immediately". After un-checking this option, links followed by selecting "Open in new Tab", or mouse-middle-click will open in a new tab without being focused. On the same option tab, you will also want "Open new windows in a new tab instead" checked (first checkbox).
This will work for most normal links. Links which are actually JavaScript code snipits will not work in a new tab because they rely on the code existing in the current page.
A change that I find useful in Firefox is to have the cursor change depending on what type of link it is hovering over. This will allow you to visually distinguish, at a basic level, what will happen when the link is clicked without having to look at the destination address. I originally found this at askvg. It is an addition to the file <profile directory>/chrome/userContent.css
(create the directory and file if they do not exist):
/* Change mouse cursor for hyperlinks that open in a new window or tab */
:link[target="_blank"], :visited[target="_blank"],
:link[target="_new"], :visited[target="_new"] {
cursor: crosshair;
}
/* Change mouse cursor for JavaScript links */
a[href^="javascript:"] {
cursor: move;
}
/* Cursor types
default - Normal select cursor
text - Text select cursor (I bar)
vertical-text - Vertical text select cursor
progress - Working in background cursor
wait - Busy cursor
help - Help cursor
crosshair - Precision select cursor
move - Move cursor
no-drop - Unavailable cursor
not-allowed - Unavailable cursor
e-resize - Horizontal resize cursor
n-resize - Vertical resize cursor
nw-resize - Diagonal resize 1 cursor
ne-resize - Diagonal resize 2 cursor
col-resize - Column resize cursor
row-resize - Row resize cursor
*/
Beyond that, it is unclear in what context you want to do this in, or at least to what extent you are willing to go to accomplish this. Your mentioning having windows/tabs open in the background and closing on their own implies that you do not actually need the user to view the window/tab. Is it that you just want a request to have been made of some URLs? Would using XMLHttpRequest
be sufficient?
You want this for yourself, so if you go the route of a Firefox extension then it is quite easy to open tabs and windows and not have them be focused. It can be done with addTab().
It would be helpful for you to describe what it is that you are overall attempting to accomplish and the context in which you are doing so.
Additional information:
Based on the additional information which you have described what you need is to write a Firefox extension which can give you complete control of popups and tabs to have them work the way you desire. For what it sounds like you desire you should see (at least) the following Mozilla documentation:
Copying an example on Tabbed browser:
// Add tab (without it becoming active)
gBrowser.addTab("http://www.google.com/");
// Add tab, then make active
gBrowser.selectedTab = gBrowser.addTab("http://www.google.com/");
From Tabbed browser:
Opening a URL in the correct window/tab
There are methods available in chrome://browser/content/utilityOverlay.js that make it easy to open URL in tabs such as openUILinkIn and openUILink.
openUILinkIn( url, where, allowThirdPartyFixup, postData, referrerUrl ) where:
- "current" current tab (if there aren't any browser windows, then in a new window instead)
- "tab" new tab (if there aren't any browser windows, then in a new window instead)
- "tabshifted" same as "tab" but in background if default is to select new tabs, and vice versa
- "window" new window
- "save" save to disk (with no filename hint!)
Also from Tabbed browser, an example of code for an overlay extension which
will open a URL in a new tab, an existing tab, or an existing window based on which mouse button was pressed and which hotkeys (ex: Ctrl) are being held. The code given is for a menuitem, but will work equally well for other XUL elements. This will only work in an overlay of browser.xul.
XUL:
<menuitem oncommand="myExtension.foo(event)" onclick="checkForMiddleClick(this, event)" label="Click me"/>
JS:
var myExtension = { foo: function(event) { openUILink("http://www.example.com", event, false, true); } }