0

I need to open a new tab in browser and focus back on the previous one with the key combination: Crtl+Tab+Shift. I read most of the solutions here and they are deprecated from JS now. If there is any other approach, please share.

wittich
  • 2,079
  • 2
  • 27
  • 50
elenaHristova
  • 611
  • 1
  • 8
  • 16
  • 1
    Possible duplicate of [Open a new tab in the background?](https://stackoverflow.com/questions/10812628/open-a-new-tab-in-the-background) – mx0 Jul 12 '17 at 18:45
  • It isn't a duplicate in that the user wants to open a tab and then revert to the tab that opened that tab... Although you are probably right in that "Open a new tab in the background" is the actual behaviour they should be aiming for. The only way to do such events would be using something like Selenium, which would be a brutal solution. – Quaternion Jul 23 '17 at 01:32

2 Answers2

0

I don't think you can simulate this because it would be highly safety problem that a browser can enter key events for you.

Just imagine the browser would enter Crtl+Shift+Esc and your task manager would open and stuff like that.

The question is what exactly is your goal? Maybe there is just another way to reach it.

If you want to stay in your browser tab and just show other content to the user on click or something you could do it with an iframe or just show the content in a fancybox or something like that.

wittich
  • 2,079
  • 2
  • 27
  • 50
-1

Key events are possible with javascript.

So I think you could say

document.addEventListener('keydown', function(event) {
  if (event.code == 'ControlLeft' && 'ctrlKey' && 'Tab') {
    window.open('http://www.eeedddö.de','_blank');
  }
});

Problem is the Strg+Tab key just switches your Browser Tab so I think you need an other key kombination without Strg+Tab key.

wittich
  • 2,079
  • 2
  • 27
  • 50
  • CTRL+Tab+Shift is the combination I want to simulate without actually entering the key combination because it is the combination used in Chrome, IE and Mozilla. – elenaHristova Jul 12 '17 at 10:08