Programmatically open new pages on Tabs
You can't directly control this, because it's an option controlled by Internet Explorer users.
Opening pages using Window.open with a different window name will open in a new browser window like a popup, OR open in a new tab, if the user configured the browser to do so.
Opening new tab programmatically without refreshing referring page?
As Keith wrote earlier:
The current code you are showing won't cause the current page to refresh,. I'm assuming your running this code on a Form, it's the form submitting that causes the refresh not this. You can use event.preventDefault on your form to stop that.
This was indeed my problem, and calling event.preventDefault() solved it. Thanks, Keith!
open a new browser tab in background programmatically
Back when popup ads were a thing, this was called a "popunder" window. Popunders used to do something like this:
var popupWindow = window.open(...);
popupWindow.blur();
window.focus();
Popup blocking kind of messed around with what does and doesn't work, though- your mileage may vary.
Open new tab in background leaving focus on current tab - Chrome
As you want this for personal usage, and you do not mind using an extension, then you can write your own one.
Writing a chrome extension to achieve your required behavior is actually super easy, All you need to know is how to open/close tabs from the extension.
The following page describes the whole API
Here is an example :
1 - Create a manifest.json
file, and ask for the tabs
permission
{
"name": "blabla",
"version": "0.1",
"permissions": ["tabs"],
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Open a background tab every x time"
},
"manifest_version": 2
}
2 - Create background.js
script in the same folder
const INTERVAL = 5000;
setTimeout(function(){
chrome.tabs.create({url: "https://www.stackoverflow.com", active: false }, tab =>{
setTimeout(function(){
chrome.tabs.remove(tab.id);
},INTERVAL);
});
},INTERVAL);
You can download it from here too
Note: Please note the
active
parameter here , it defines whether the tab should become the active tab in the window. Does not affect
whether the window is focused
3 - Use the extension in chrome
- If you are using the download link, then unpack the archive
- Navigate from chrome menu to extensions
- Enable the developer mode in the top right corner
- Click on
Load Unpacked
button to select the extension folder - The extension will run automatically
Shortcut (programmatically) open a link in a new tab without focus to that tab
The way I have seen this done before is for the webpage to listen for key presses (e.g., j/k) and simply focus() the desired link. Then, when the user presses Enter or Ctrl-Enter, he is simply performing the default operation on the focused link.
Sure enough, when I type this into the javascript console on a Google search result page, I see the links that are being focused.
document.addEventListener('focus', function(e) {console.log(e.target)}, true);
So Google is still using the same technique, although it's not so obvious because they hide the dotted outline around the focused link using CSS (a.noline{outline:0}
).
Open a new window (or new tab) programmatically instead of always a popup
$window.open
is really just the same as window.open
, which doesn't have much to do with angular. In terms of opening in a new window or tab, that is up to the user, and the settings they have initialised with their browser.
Also the same goes for anchor links with target="_blank"
.
How to open a new browser window programmatically
You can use Desktop.getDesktop().browse(new URL("http://google.com").toURI());
to open a new tab but you cannot open a new window. That will only happen if the user does not have a internet browser up.
https://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html#browse(java.net.URI)
Related Topics
Get the Index of the Object Inside an Array, Matching a Condition
Equivalent of String.Format in Jquery
Is Node.Js Native Promise.All Processing in Parallel or Sequentially
What Does $(Function() {} ); Do
Setting Query String Using Fetch Get Request
How to Execute Promises Sequentially, Passing the Parameters from an Array
Caching a Promise Object in Angularjs Service
Recursive Matching with Regular Expressions in JavaScript
Variable Scope in D3 JavaScript
How to Return Values from Async Functions Using Async-Await from Function
Can a PDF File's Print Dialog Be Opened with JavaScript
How to Check If Iframe Is Loaded or It Has a Content
Filtering Array of Objects with Arrays Based on Nested Value
How to Profile JavaScript Execution
How to Parse a Time into a Date Object from User Input in JavaScript
Nodejs Callbacks Simple Example
JavaScript Document.Write Replaces All Body Content When Using Ajax