How to select a browser tab from another tab? - javascript

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

Related

how to open new tab by overriding the already opened tab onclick of a button?

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

How to close the Current opened Tab and go back to previous (Parent) Tab

It is not a duplicate question please
Dear All,
I am new to Jquery, Please help me how to close the Current opened Tab in a application using Jquery on click of YES/Confirm button in a model window as shown in a image.
I have tried below function, its not closing current tab instead it closed all the tabs. Please help me
window.open('', '_self').close();
window.top.close();
window.close();
before you close the current tab, you need to open it using "window.open()".
the window.close button works only the windows that opened by it.
You can close the current tab with this javascript line:
window.top.close();
But there are things that you should keep in mind:
This will only work if the tab is also opened programmatically.
By using window.open();, you can close the opened tab with the javascript line above.
Not all browsers support this solution
You can also visit this link for reference. I hope this helps.

I want to open link on another tab but do not want to lose focus from my current tab

I want to open link on another tab but do not want to lose focus from my current tab.
I have tried enough doing it but unable to execute this behavior.
Any kind of help is really appreciated. Thanks!

Single mouse click to open new tab + modal window at same time

See for example:
http://www.retailmenot.com/view/macys.com
When you click on one of the buttons, it both automatically opens a new tab, and pop out their modal window.
What are the possible ways to do this?
They seem to do both actions with Javascript. They actually do something that keeps the window in the current tab and not on the one that was opened. How is it done?
In general, Can I achieve these two actions (nevermind if focus is on new window) with a regular form submission with target=_blank the new tab, and some class to pop the modal window? What should the javascript look like?
Is there any way to do this without javascript at all?
Basically I'm looking for practices that are supported from IE8+, and cross browser compliant.
See this : http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
You can open your js modal also inside myFunction() function.

How to set focus to already opened tab in firefox?

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!

Categories