I have a link which opens a page in a new tab in firefox.
<a target="_default" href='/portal.html' >
Go to Portal
</a>
However when I click this link again ,it refreshes the opened tab and doesn't set focus to it , so users have no way to know that tab is opened .
Is there any way by which I can grab the opened tab and set focus on subsequent clicks after opening it once Or any other workaround .
Thanks.
For getting the focus using a tabhandler name may help.. suppose we have
win = window.open("https://www.google.com", "test");
win.focus();
now every time the first line of above code runs the browser will first find the tab with the name test and reload it with the url https://www.google.com and in case it does not find a tab with the name test it will open a new one. On the run of the second line it will set the focus to the same tab loaded from the first line.
I had a similar problem in my project.
Luckily, whenever I needed to set focus on already opened tab, it also needed to be refreshed.
So I did it with the following trick, which first opened again tab with same href and target, got reference of that window back, closed it, and opened again with same parameters.
popup = window.open('/popup.html', '_popup')
popup.close()
popup = window.open('/popup.html', '_popup')
No.
Each tab normally runs in a separate process sandbox. It's just not possible.
At max you can try target="_blank".
You can probably use _blank and some JS code that closes a previously opened tab for the same URL using cookie tracking.
The page (that you are opening in the new tab) should be built in such a way that it writes out a cookie with some value (say current time in millis). It should also have some kind of a periodic poller that checks the value of this cookie and closes itself when the value is seen to be changed. the only way this value can change is when the same url is opened in another tab/popup.
Disclaimer: Not sure if browsers will allow window.close without it being user triggered though!
Related
I am just trying to open new tab onclick of a button. on second click i want to open new tab by overriding the already existing tab which was opened on first click.
That is a rather difficult thing to do - you would need to disable clicking on the first page, and instead send a message to another window if open already, and make it reload. Could be possible in Chrome and some specific browsers. I'd just find another way.
If you want to do this, this is the way: https://davidwalsh.name/window-postmessage
First of all, happy holidays to everyone.
I have an anchor element that fires two page redirects - one through the href attribute, one through jQuery.
<a id="myClick" target="_blank" href="http://www.google.ca">Google</a>
$('#myClick').on('click', function () {
window.location = 'http://www.stackoverflow.com';
});
This works fine, but the new tab gains focus. I'd like the original tab to keep the focus for the user. I did give window.focus() a go but, as assumed, it didn't work.
I also did try working with the fiddle from this answer but it only fired the new tab and the original page (jsfiddle) remained the same URL. My edited Fiddle from linked answer
How could I go about having the original tab keep the focus? Is it out of my hands?
You can't open tabs in the background using javascript because this is set in the user's preferences in about:config, which you have no control over. The setting is:
browser.tabs.loadDivertedInBackground=true
I haven't found a single answer able to tell me what's the right way to open a popup.
Times have changed, and popups have been mostly replaced with fancybox-like boxes. However, there are still times when popups are needed.
For those cases, I don't want my popup to be blocked by the browsers.
What's the right way to open a popup without it being blocked? Even if it opens a new tab in the browser. I just want my popup to be open, and have control of it from the parent or vice versa.
Popup blockers will block any popup, unless it is opened because of an user action.
If the user clicks on a link, and a popup is opened in the click listener of that link, the popup blocker knows the user want to open something and will not (or should not) block the popup.
What you cannot do:
open a popup when the page is opened or closed
open a popup after a certain interval
open a popup after something asynchronous happens
What you can do:
open a popup in the on click listener
using target="_blank" in a anchor tag
You can access both windows with JavaScript variables:
if you use window.open, the parent can have a reference to the popup by assigning the result of window.open to a variable. Check out this article at W3Schools.
If the popup needs to have access to the window who has opened it, you can use window.opener. Check out this question.
try this, it works for me
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
redirectWindow.location;
});
Js fiddle for this is here https://jsfiddle.net/safeeronline/70kdacL4/2/
if you want to open new tab after ajax call see this fiddle http://jsfiddle.net/safeeronline/70kdacL4/1/
I want to select a browser tab from another tab. For example one of my web app is opened in a browser and I opened a link in another tab. Now I want to select my first tab using a shortcut key like "CTRL+M" or something like that.
How can I do this?
You are not able to select anything outside your HTML-structure programmatically. The only option you have, is to close the current tab so it may jump back to the last tab:
window.close();
Even this approach is based on some assumptions and unreliable. Don't go that way ;)
As far as I know this only works if one of the tabs is a popup of another tab. Then you can use
window.opener.focus();
To focus the tab that opened the pop up
and
popupName.focus();
To focuse the pop up
Can anyone please tell me how can I detect if user has already opened the link/url tab and is it possible to redirect a link to a active browser tab if the url is already opened?
Eg: User clicks on the link and js code will open a new tab in browser.Now if user again clicks on the link I want him to redirect to the active session instead of opening a new tab.
I read the below post but unable to implement my logic according to them:
Java: ensure web application open only in one browser tab
Possible to detect if a user has multiple tabs of your site open?
I am using simple window.open(url) to open my url in new tab.
Thanks....
if you give a name to the opened window it will reopen the same the second time
window.open(url,"mypopup");
use the target/window name in javascript do that
window.open(yoururl, youruniquewindowname)
example
window.open("https://stackoverflow.com/", "stack_unique_123")
if a window with stack_unique_123, is already open, the "https://stackoverflow.com/" will be reload in that window, preventing a new one to be open.