Window open tab new windows

Visual Studio Code open tab in new window

I am trying to open a tab in a new window in Visual Studio Code so I can move it to another screen. If I drag the tab the other screen, a file is created. Is there a shortcut to open a tab in a new Visual Studio Code window so I can move it to another screen?

8 Answers 8

On Windows and Linux, press Ctrl + K , then release the keys and press O (the letter O, not Zero).

On macOS, press command + K , then O (without holding command ).

This will open the active file tab in a new window/instance.

Until they support it, you can try the following workarounds:

1. Duplicate Workspace in New Window [1]

The Duplicate Workspace in new Window Command was added in v1.24 (May 2018) to sort of address this.

  1. Open up Keyboard Shortcuts Ctrl + K , Ctrl + S
  2. Map workbench.action.duplicateWorkspaceInNewWindow to Ctrl + Shift + N or whatever you’d like

2. Open Active File in New Window [2]

Rather than manually open a new window and dragging the file, you can do it all with a single command.

  1. Open Active File in New Window Ctrl + K , O

3. New Window with Same File [3]

As AllenBooTung also pointed out, you can open/drag any file in a separate blank instance.

  1. Open New Window Ctrl + Shift + N
  2. Drag tab into new window

4. Open Workspace and Folder Simultaneously [4]

VS Code will not allow you to open the same folder in two different instances, but you can use Workspaces to open the same directory of files in a side by side instance.

  1. Open Folder Ctrl + K , Ctrl + O
  2. Save Current Project As a Workspace
  3. Open Folder Ctrl + K , Ctrl + O
Читайте также:  Не запускается обычная загрузка windows

How to Open URL in a New Tab with Javascript

Use-Cases of this Tutorial

  • Know how to open a URL in a new tab using Javascript.
  • Know how to make sure that new tab is not blocked by browser through its popup blocker.
  • Know how to communicate between the original tab and the newly opened tab.

This tutorial covers opening a new browser window tab using Javascript, and other concepts around it.

Opening a New Tab with window.open()

A URL can be opened in a new tab in Javascript using the window.open() method, and giving _blank as its second parameter.

Preventing Browser Popup Blockers

If window.open() is not called directly upon a user action, browser in general will block the new popup tab.

See the below example where a new window tab is being opened 2 seconds after the user clicks on a button. This is obviously not a user generated action, but rather «code» trying to open a new window. The browser will block the popup in such a case.

In general follow these rules for a seamless opening of a new tab or window :

  • Make sure that window.open() is called upon an explicit user generated event. Even if a trigger is made to fire this event through code, browser may block the new window.
  • Make sure that call to window.open() is not nested in some deep inner function. For example a function calling another function, which in turn calls another function which finally calls window.open() may result in being blocked. In general keep the code to open new window tab as simple as possible.

To make the above scenario (popup getting blocked after 2 seconds) make workable, the solution would be to show a new button to the user after 2 seconds. On clicking the new button a call to window.open() can be made. Browser will not block this tab.

Communication Between the Original Window Tab and New Tab

Communication from Parent Tab to Child Tab

The return value of window.open() represents the handle to the new window. This handle can be used to control the new window.

The parent window can even execute code in the new child window.

Читайте также:  Параметры разъема windows 10 где находится

Communication from Child Tab to Parent Tab

javascript window.location in new tab

I am diverting user to some url through window.location but this url opens in the same tab in browser. I want it to be open in new tab. Can I do so with window.location? Is there another way to do this action?

7 Answers 7

I don’t think there’s a way to do this, unless you’re writing a browser extension. You could try using window.open and hoping that the user has their browser set to open new windows in new tabs.

The second parameter is what makes it open in a new window. Don’t forget to read Jakob Nielsen’s informative article 🙂

You can even use

This will open it on the same tab if the pop-up is blocked.

This works for me on Chrome 53. Haven’t tested anywhere else:

with jQuery its even easier and works on Chrome as well

Rather going for pop up,I personally liked this solution, mentioned on this Question thread JavaScript: location.href to open in new window/tab?

We have to dynamically set the attribute target=»_blank» and it will open it in new tab. document.getElementsByTagName(«a»)[0].setAttribute(‘target’, ‘_blank’)

If you want to open in new window, get the href link and use window.open

var link = document.getElementsByTagName(«a»)[0].getAttribute(«href»);

Don’t provide the second parameter as _blank in the above.

Open a new tab/window and write something to it?

I’m using Execute JS to write and test Javascript code within Firefox. I want to open a new tab/window and write something to it and I tried

However I always get this error

[Exception. «The operation is insecure.» code: «18» nsresult: «0x80530012 (SecurityError)»

Is there any way to get through this exception?

3 Answers 3

Edit: As of 2018, this solution no longer works. So you are back to opening about:blank in a new window and adding content to it.

Don’t «write» to the window, just open it with the contents you need:

Top-level navigation to data URLs has been blocked in Chrome, Firefox (with some exceptions), IE, and Edge (and likely other browsers to boot). They are apparently commonly used for phishing attacks, and major browser vendors decided that the danger outweighed the value provided by legitimate use cases.

Читайте также:  Ваша система не была исправлена против критических уязвимостей безопасности windows faceit

This Mozilla security blog post explains that Firefox will block

but will not block

  • User explicitly entering/pasting «data:…» into the address bar
  • Opening all plain text data files
  • Opening «data:image/*» in top-level window, unless it’s «data:image/svg+xml»
  • Opening «data:application/pdf» and «data:application/json»
  • Downloading a data: URL, e.g. ‘save-link-as’ of «data:…»

As for how to actually open HTML in a new tab or window, this should be sufficient:

Chrome, Javascript, window.open in new tab

In chrome this opens in a new tab:

this opens in a new window (but I’d like this to open in a new tab as well:

Is this feasible?

8 Answers 8

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.

EDIT:

A more detailed explanation:

1. In modern browsers, window.open will open in a new tab rather than a popup.

2. You can force a browser to use a new window (‘popup’) by specifying options in the 3rd parameter

3. If the window.open call was not part of a user-initiated event, it’ll open in a new window.

4. A “user initiated event” does not have to the same function call – but it must originate in the function invoked by a user click

5. If a user initiated event delegates or defers a function call (in an event listener or delegate not bound to the click event, or by using setTimeout for example), it loses it’s status as “user initiated”

6. Some popup blockers will allow windows opened from user initiated events, but not those opened otherwise.

7. If any popup is blocked, those normally allowed by a blocker (via user initiated events) will sometimes also be blocked. Some examples…

Forcing a window to open in a new browser instance, instead of a new tab:

The following would qualify as a user-initiated event, even though it calls another function:

The following would not qualify as a user-initiated event, since the setTimeout defers it:

Оцените статью